如何让菜单层固定

js部份:

function toolbar(el) { el = typeof el == 'string' ? document.getElementById(el) : el; var elTop = el.offsetTop; var sTop = 0; window.onscroll = function () { sTop = document.body.scrollTop || document.documentElement.scrollTop; if (sTop > elTop) { el.style.top = "0"; el.style.position = "fixed"; document.getElementById("zuanti").style.marginTop="50px"; } else { el.style.top = elTop + 'px'; el.style.position = "absolute"; document.getElementById("zuanti").style.marginTop="50px"; } } } toolbar('nav');

html部份:
<div id="nav">
  <ul>
  <li><a href="http://www.xingyunba.com/" title="首页">姓名测试</a></li>
  <li><a href="http://www.xingyunba.com/sm/">免费算命</a></li>
  <li><a href="http://www.xingyunba.com/ceshi/">心理测试</a></li>
  <li><a href="http://www.xingyunba.com/astro/">十二星座</a></li>
  <li><a href="http://www.xingyunba.com/shuxiang/">十二生肖</a></li>
  <li><a href="http://www.xingyunba.com/paipan/">在线排盘</a></li>
  <li><a href="http://www.xingyunba.com/fengshui/">风水知识</a></li>
  <li><a href="http://www.xingyunba.com/qinglv/">缘分测试</a></li>
  <li><a href="http://www.xingyunba.com/zgjm/">周公解梦</a></li>
  <li><a href="http://www.xingyunba.com/ask/" title="起名大师提供免费宝宝取名咨询">免费起名</a></li>
  </ul>
 </div>  
posted @ 2013-02-27 20:34  chinall  阅读(215)  评论(0编辑  收藏  举报