DIV position change while scrolling down using scrollTop(); - jQuery

落花浮王杯 提交于 2019-12-24 08:37:10

问题


I'm stuck with this, hope any of you can help me out.

I have this HTML:

<body>
    <div id="one"></div>
    <div id="two"></div>
    <div id="three"></div>
<body>

With this CSS:

#one, #two, #three {
    width: 100%;
    height: auto;
}

And this jQuery:

$(window).scroll(function(){
var y = $(window).scrollTop();
var one = $('#one').height();
var two = $('#two').scrollTop();
var three = $('#three').scrollTop();

var pos_one = 310;
var pos_two = 454;
var pos_three = 596;

if( y > one ){
    $("#header").fadeIn(200);
} else {
    $('#header').fadeOut(200);
}

if( (y > one) && (y < two) ) {
    $('.bubble').animate({
        "left" : pos_two + "px" 
    }, 300);
}

if( (y > two) && (y < three) ) {
    $('.bubble').animate({
        "left" : pos_three + "px" 
    }, 300);
}
});

So, #header is fading in when I reach #two, that's working. The problem I have is that .bubble div is not moving when I reach the other sections while scrolling.

What am I doing wrong? Any help would be much appreciated!


回答1:


simply use overflow property

just include overflow:hidden within your css something like this....

#one, #two, #three {
    width: 100%;
    height: auto;
    overflow:hidden; 
}

you can use property value as per your need. here is the reference link overflow property link

Let me know it will help you or not ???



来源:https://stackoverflow.com/questions/12990191/div-position-change-while-scrolling-down-using-scrolltop-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!