jQuery实现网页顶部固定导航效果代码
本文实例讲述了jQuery实现网页顶部固定导航效果代码。分享给大家供大家参考,具体如下:
运行效果截图如下:
具体代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="jquery-1.7.2.min.js" ></script> <script type="text/javascript"> $(function(){ $("#wrap ul li ").css("width",760 / $("#wrap ul li").size()); $(window).scroll(function(){ var h = $(this).scrollTop()+2; $("#wrap").css("top",h); }); $("#wrap ul li:even").css("background","#ddd") $("#wrap ul li").hover(function(){$(this).css("background","#0f0");},function(){$(this).css("background","");}); }); </script> <style type="text/css"> #wrap{position:absolute; top:2px; left:0px; width:100%; height:20px; background:#f00;} #wrap ul{list-style:none; width:760px; margin:0 auto; padding:0; background:#fff;} #wrap ul li{float: left; text-align:center;} #test{height:2000px; background:#f0f; margin:0; padding:0; border:1px solid black;} </style> </head> <body> <div id="wrap"> <ul> <Li>首页</Li> <li>图片</li> <li>新闻</li> <li>软件</li> <li>图片</li> <li>新闻</li> <li>软件</li> <li>图片</li> <li>新闻</li> <li>软件</li> </ul> </div><div id="test"></div> </body> </html>
希望本文所述对大家jQuery程序设计有所帮助。
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17