开发者

How to add boundaries to a postion:fixed element?

I want to know how you would add a stopping p开发者_运维知识库oint/boundary to a postion:fixed menu that follows you as you scroll. I wanted to have it stop when you get close to a particular point.


As Saeed said—something like this:

$(document).ready(function() {
    $(window).bind('scroll', function(e) { 
        if ($(this).scrollTop() < SOME_PIXEL_VALUE ) { 
            $(YOURELEMENT).css({'position': 'fixed', 'top': '25px'}); 
        } else {
            $(YOURELEMENT).css('position','absolute', 'top': 'SOME_PIXEL_VALUE); 
        }
    });
});


You should use JavaScript or jQuery and hook to the scroll event. When you got close to the intended point, you should change the CSS or class of your fixed element to suit your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜