Fixed header whilst scrolling

放肆的年华 提交于 2019-12-08 13:57:29

问题


I am using a jquery scripts to cause my header to remain fixed to the top whilst scrolling. But at the moment, it's animated and that's quite a distraction. Is there a way I can modify the script so that it doesn't animate?

JQuery;

<script type="text/javascript">
$().ready(function() {

        var $scrollingDiv = $("#header");

        $(window).scroll(function(){            
            $scrollingDiv.stop().animate({"marginTop": ($(window).scrollTop() + 0) + "px"}, "fixed" );          
        });
    });


</script>

Html;

<div id="header">Content</div>

回答1:


Take a look at the link below as a simple solution to your problem.

http://www.cssplay.co.uk/layouts/basics2.html

EDIT: Also the solution from the above link should be cross-browser compatible




回答2:


Add to the style of the header position:fixed;.



来源:https://stackoverflow.com/questions/9684259/fixed-header-whilst-scrolling

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