Position fixed when scrolled passed certain amount of pixels

前端 未结 5 1796
傲寒
傲寒 2021-02-06 17:10

I\'m looking for a way to position the #header element of my page as \"Fixed\" only after having scrolled downward for about 170 pixels.

Above the header is a banner, so

5条回答
  •  长情又很酷
    2021-02-06 17:30

    Here is a demo of a jquery plugin that takes care of this. Similar to John's answer above, but the plugin takes the solution a bit farther.

    Demo: http://jsfiddle.net/ZczEt/

    Plugin and source: https://github.com/bigspotteddog/ScrollToFixed

    Usage:

    $(document).ready(function() {
        $('.header').scrollToFixed();
    });
    

提交回复
热议问题