jQuery:传递scrollTop值后隐藏元素

时间:2014-02-19 20:54:09

标签: javascript jquery html css

我希望在我的滑块传递scrollTop()值为200px时隐藏div。我已经查看了这个article并尝试将其用作我想要的模板。我有以下代码,但它没有隐藏元素。直播site

function removeArrow() {
$(window).scroll(function() {
    if($('.portfolio-sliders:first-child').scrollTop() > 100) { //use `this`, not `document`
        $('.scrl-dwn').css({
            'display': 'none'
        });
    }
 });
}

更新

我已按代码更新:

function removeArrow() {
$(window).scroll(function() {
    var slider = $('.portfolio-sliders:first-child').position.top;
    if(slider >= 10) { 
        $('.scrl-dwn').hide();
    }
});
}

应该有用,但不是......

3 个答案:

答案 0 :(得分:2)

职位是一种功能,而不是财产。您需要使用()调用该函数:

var slider = $('.portfolio-sliders:first-child').position().top;

答案 1 :(得分:1)

用此代码替换整个removeArrow函数。 (如果您打开实时站点,并在控制台中运行它,您可以看到它正在运行)。

scroll事件从未被解雇,因此我处理了鼠标轮事件。

$(window).bind('DOMMouseScroll mousewheel', function() {
    var div = $(".portfolio-sliders:first-child"),
        top = div.position().top,
        display = top < 400 ? 'none' : '';
    $('.scrl-dwn').css({ 'display': display });
});

答案 2 :(得分:0)

使用此:

$(window).scroll(function(){
         if ($(window).scrollTop() > 660)
         {
             $(".Left-Section").css("position", "fixed");
             $(".Center-Content").css("margin-top", "0");
             $(".Right-Nav img").css("transform", "rotate(360deg)");
         }