scrolling div fixed until footer [closed]

不羁岁月 提交于 2019-12-13 09:28:36

问题


Hi I'm hoping somebody can help me out i've been looking up a lot of tutorials to see if this could be done easily I'm new to jQuery, I'm trying to scroll a fixed div down the page but the div is moving into the footer when it reaches the bottom. Im thinking in the jquery to add something like a scroll control and then when it reached a certain amount of pixels down the page to change the positioning with .css in the jquery. I'm not to sure how to go about it properly though. I've made a VERY simplified version in jsfiddle to kind of illustrate what i'm trying to do, any help would be appreciated. Thanks

[http://jsfiddle.net/wVhCR/]


回答1:


Here's the jQuery which should help. Just make a css class that changes the box how you want it.

$(document).on('scroll', function(){
    var scroller = $('#scroller');
    var footer = $('#footer');
    var scroll_bot = scroller.offset().top + scroller.height();
    var footer_top = footer.offset().top;

    alert(scroll_bot);
    if(scroll_bot > footer_top){
        scroller.addClass('classThatMakesBoxActRight');
    }else{
        scroller.removeClass('classThatMakesBoxActRight');
    }
});


来源:https://stackoverflow.com/questions/18359491/scrolling-div-fixed-until-footer

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