开发者

How to add boundaries to a postion:fixed element?

开发者 https://www.devze.com 2023-03-24 00:26 出处:网络
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

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

精彩评论

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