【问题标题】:Make hidden div appear on scroll in WordPress让隐藏的 div 出现在 WordPress 的滚动条上
【发布时间】:2019-04-04 05:52:43
【问题描述】:

有几篇关于这个的帖子,但由于某种原因,我似乎无法让它工作。我有一个浮动按钮,我想在滚动时出现。我已将脚本添加到我的标题和 css 中。不知道我在这里做错了什么。

我尝试过的一些帖子:

Show div on scrollDown after 800px

Make div appear on scroll in wordpress

Make <div> appear upon scrolling

--PHP--

add_action('wp_header', 'subscribe_float');
function subscribe_float() {
?>
    <script type="text/javascript"> 
        jQuery(function($) {
            $(document).scroll(function () {
                var y = $(this).scrollTop();
                if (y > 50) {
                    $('#custom_html-12').slideDown();
                } else {
                    $('#custom_html-12').slideUp();
                }
            });
        });
    </script>
<?php } ?>


--CSS--

#custom_html-12 {
    background: #fbbd14;
    position: fixed;
    bottom: 55px;
    z-index: 999;
    right: 20px;
    padding: 5px;
    color: #fff;
    border-radius: 4px;
    display: none;
}

【问题讨论】:

    标签: javascript wordpress


    【解决方案1】:

    钩子是wp_head,而不是wp_header。因此,您的代码应该是:

    add_action('wp_head', 'subscribe_float');
    

    【讨论】:

    • 谢谢。感谢您的宝贵时间和帮助。
    猜你喜欢
    • 2014-10-02
    • 2014-11-17
    • 2015-03-16
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    相关资源
    最近更新 更多