滚动时固定标题 [英] Fixed header whilst scrolling
本文介绍了滚动时固定标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用一个jquery脚本来使我的标题在滚动时保持固定在顶部.但是目前,它是动画的,这很让人分心.有没有一种方法可以修改脚本以使其不动画?
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>
推荐答案
看看下面的链接,这是解决问题的简单方法.
Take a look at the link below as a simple solution to your problem.
另外,上述链接中的解决方案应与跨浏览器兼容
Also the solution from the above link should be cross-browser compatible
这篇关于滚动时固定标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文