如何用jQuery做到这一点?jQuery:固定在Facebook和Twitter的顶级菜单
我知道如何做到这一点与CSS(位置:固定),但IE问题(不知道固定位置)担心我。
也许有一些插件,但我没有找到它...
谢谢!
如何用jQuery做到这一点?jQuery:固定在Facebook和Twitter的顶级菜单
我知道如何做到这一点与CSS(位置:固定),但IE问题(不知道固定位置)担心我。
也许有一些插件,但我没有找到它...
谢谢!
关于css位置固定以及如何在IE6及更高版本上完成此操作,有一篇很棒的文章here。如果你需要任何帮助,请告诉我。
position: fixed;
是position: absolute; position: relative;
和position: static;
的替代方案。 position: fixed;
与position: absolute;
基本相同,区别在于当用户滚动页面时,元素不会随其滚动,而只是说明它在哪里
问题是,最受欢迎的浏览器--Windows Internet Explorer不理解它,而不是恢复到position: absolute;
,这会比没有好,它将恢复到由CSS标准指定的position: static;
。这与完全没有定位相同。请注意,从测试版2向上的IE 7支持position: fixed;
有些作者使用> CSS选择器来隔离Internet Explorer,并将该元素完全放置在该浏览器中,而没有滚动效果。
div#fixme { position: absolute; left: 0px; top: 0px; }
body > div#fixme { position: fixed; }
或
div#fixme {
left: expression(document.body.scrollLeft + 'px');
top: expression(document.body.scrollTop + 'px');
}
body > div#fixme { position: fixed; left: 0px; top: 0px; }
我注意到一些有点奇怪。如果我将该值赋值给一个变量,然后使用它将其分配给内联表达式,则它将在Internet Explorer 5.5和6中进行更新。它稍微不平稳,但不像许多脚本驱动的定位技术那样糟糕。
top: expression((ignoreMe = document.body.scrollTop) + 'px');
ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop
或
<style type="text/css">
#fixme {
/* Netscape 4, IE 4.x-5.0/Win and other lesser browsers will use this */
position: absolute; right: 20px; bottom: 10px;
}
body > div#fixme {
/* used by Opera 5+, Netscape6+/Mozilla, Konqueror, Safari, OmniWeb 4.5+, iCab, ICEbrowser */
position: fixed;
}
</style>
<!--[if gte IE 5.5]>
<![if lt IE 7]>
<style type="text/css">
div#fixme {
/* IE5.5+/Win - this is more specific than the IE 5.0 version */
right: auto; bottom: auto;
left: expression((-20 - fixme.offsetWidth + (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth) + (ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft)) + 'px');
top: expression((-10 - fixme.offsetHeight + (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight) + (ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)) + 'px');
}
</style>
<![endif]>
<![endif]-->
看看这个页面:http://tagsoup.com/cookbook/css/fixed/它会允许你只使用,而不必使用JavaScript CSS 。 – 2011-12-13 17:21:49