(Created page with "$(function () { var ie6 = /msie 6/i.test(navigator.userAgent) , dv = $('#fh5co-header-section'), st; dv.attr('otop', dv.offset().top); //存储原来...") |
|||
Line 1: | Line 1: | ||
+ | <script> | ||
$(function () { | $(function () { | ||
var ie6 = /msie 6/i.test(navigator.userAgent) | var ie6 = /msie 6/i.test(navigator.userAgent) | ||
Line 14: | Line 15: | ||
}); | }); | ||
// JavaScript Document | // JavaScript Document | ||
+ | </script> |
Revision as of 13:45, 8 October 2017
<script>
$(function () {
var ie6 = /msie 6/i.test(navigator.userAgent) , dv = $('#fh5co-header-section'), st; dv.attr('otop', dv.offset().top); //存储原来的距离顶部的距离 $(window).scroll(function () { st = Math.max(document.body.scrollTop || document.documentElement.scrollTop); if (st >= parseInt(dv.attr('otop'))) { if (ie6) {//IE6不支持fixed属性,所以只能靠设置position为absolute和top实现此效果 dv.css({ position: 'absolute', top: st }); } else if (dv.css('position') != 'fixed') dv.css({ 'position': 'fixed', top: 0 }); } else if (dv.css('position') != 'static') dv.css({ 'position': 'static' }); }); });
// JavaScript Document
</script>