简体   繁体   English

使div出现在wordpress的滚动中

[英]Make div appear on scroll in wordpress

I can't seem to figure this one out.. I'm sure it's something simple. 我似乎无法弄清楚这一点。.我确信这很简单。 My goal is to make a solid filled div slide down form the top of viewport once the user has scrolled down a bit. 我的目标是一旦用户向下滚动一点,即可使填充实心的div从视口顶部向下滑动。 I've implemented this before in a basic page but I cannot seem to get it to work in wordpress. 我之前已经在基本页面中实现了此功能,但似乎无法在Wordpress中使用它。 Here is the code I'm using: 这是我正在使用的代码:

<script type="text/javascript">  

$(document).scroll(function () {
    var y = $(this).scrollTop();
    if (y > 50) {
        $('.slide').slideDown();
    } else {
        $('.slide').slideUp();
    }

});

</script>

The div is positioned at the top, the css is: div位于顶部,css为:

.slide {
    display: none;
    position: fixed;
    top: 0;
    width: 100%;
    height: 50px;
    background: rgba(255, 255, 255, 0.97);
    z-index: 1;
}

When I remove display: none it displays, so I know this isn't an issue with the z-index. 当我删除显示时:不显示任何内容,因此我知道这与z-index无关。 I had no luck when placing the script in the footer. 将脚本放在页脚中时我没有运气。 Any ideas? 有任何想法吗? Thanks! 谢谢!

With this much info, my guess is this happens because of WordPress using noconflict. 有了这么多的信息,我猜这是由于WordPress使用noconflict而发生的。
Try modifying your code like that: 尝试像这样修改代码:

<script type="text/javascript"> 
jQuery(function($) {
    $(document).scroll(function () {
        var y = $(this).scrollTop();
        if (y > 50) {
            $('.slide').slideDown();
        } else {
            $('.slide').slideUp();
        }

    });
});
</script>

put on header.php 放在header.php

<script type="text/javascript" >

jQuery(document).scroll(function() {
    if ( jQuery(this).scrollTop() > 300) {
        jQuery('.home-link').fadeOut(1500);
        jQuery('.nav-menu a').css({ "font-weight": "bold"});
    } else {
        jQuery('.home-link').fadeIn();
        jQuery('.nav-menu a').css({ "font-weight": ""});
    }
});

</script>

beetwen <?php wp_head(); ?> beetwen <?php wp_head(); ?> <?php wp_head(); ?> and </head> <?php wp_head(); ?></head>

More explained here (Spanish): 这里有更多解释(西班牙语):

Como ocultar la cabecera de pagina WordPress al hacer Scroll + Video Como ocultar la cabecera de pagina WordPress al hacer滚动+视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM