实现鼠标滑动,让某个div固定在最上方

来源:互联网 发布:ps4合金装备vb 编辑:程序博客网 时间:2024/06/01 08:40
 var ie6 = /msie 6/i.test(navigator.userAgent);      var tableDv = $('.table-css1');      var st;      tableDv.attr('otop', tableDv.offset().top); //存储原来的距离顶部的距离      $(window).scroll(function () {          st = Math.max(document.body.scrollTop || document.documentElement.scrollTop);          if (st>= parseInt(tableDv.attr('otop'))) {              if (ie6) {//IE6不支持fixed属性,所以只能靠设置position为absolute和top实现此效果                  tableDv.css({ position: 'absolute', top: st });              }              else if (tableDv.css('position') != 'fixed') tableDv.css({ 'position': 'fixed', top: 0 });          } else if (tableDv.css('position') != 'static') tableDv.css({ 'position': 'static' });      });

<div class="table-css1">

</div>
0 0
原创粉丝点击