最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

JS实现定位式导航栏

来源:动视网 责编:小采 时间:2020-11-27 19:59:46
文档

JS实现定位式导航栏

JS实现定位式导航栏:这次给大家带来JS实现定位式导航栏,JS实现定位式导航栏的注意事项有哪些,下面就是实战案例,一起来看一下。完整代码如下:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <s
推荐度:
导读JS实现定位式导航栏:这次给大家带来JS实现定位式导航栏,JS实现定位式导航栏的注意事项有哪些,下面就是实战案例,一起来看一下。完整代码如下:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <s


这次给大家带来JS实现定位式导航栏,JS实现定位式导航栏的注意事项有哪些,下面就是实战案例,一起来看一下。

完整代码如下:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<style type="text/css"> 
*{margin:0;padding:0;} 
.nav{width:100%;position:absolute;top:150px;} 
.nav ul{width:1200px;height:50px;margin:0 auto;background:#ccc;} 
.nav ul li{width:150px;height:50px;line-height:50px;text-align:center;list-style:none;float:left;cursor:pointer;} 
.nav ul li:hover{background:#666;} 
.nav ul li a{color:#000;font-size:18px;text-decoration:none;} 
.nav .active{background:#666;} 
.cont{width:1200px;height:4500px;margin:0 auto;} 
.cont ol{width:1200px;height:4500px;margin:0 auto;} 
.cont ol li{width:1200px;height:500px;list-style:none;} 
.cont ol li p{color:#000;font-size:48px;} 
</style> 
</head> 
<body> 
<p style="height:200px;width:100%;"></p> 
<p class="nav"> 
 <ul> 
 <li class="active">page1</li> 
 <li>page2</li> 
 <li>page3</li> 
 <li>page4</li> 
 <li>page5</li> 
 <li>page6</li> 
 <li>page7</li> 
 <li>page8</li> 
 </ul> 
</p> 
<p class="cont"> 
 <ol> 
 <li style="background:#aaa"><p>page1</p></li> 
 <li style="background:#999"><p>page2</p></li> 
 <li style="background:#666"><p>page3</p></li> 
 <li style="background:#333"><p>page4</p></li> 
 <li style="background:#bbb"><p>page5</p></li> 
 <li style="background:#aaa"><p>page6</p></li> 
 <li style="background:#ccc"><p>page7</p></li> 
 <li style="background:#000"><p>page8</p></li> 
 </ol> 
</p> 
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script> 
<script type="text/javascript"> 
$(".nav ul li").click(function(){ 
 var index=$(this).index(); 
 var i=150+index*501+'px' 
 $("html,body").animate({scrollTop:i},500) 
 }) 
$(window).scroll(function(){ 
 if($(window).scrollTop()>150){ 
 $(".nav").css({"position":"fixed","top":"0px"}) 
 } 
 else{ 
 $(".nav").css({"position":"absolute","top":"150px"}) 
 } 
 for(var x=0;x<8;x++){ 
 var i=150+x*500 
 if($(window).scrollTop()>i && $(window).scrollTop()<i+500){ 
 $(".nav ul li").eq(x).addClass("active").siblings().removeClass("active")} 
 } 
}) 
</script> 
</body> 
</html>

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

jquery怎样做出分页效果

jQuery在添加元素时无法触发绑定事件怎么处理

JS怎样实现左右两侧菜单添加与移除

如何用jQuery封装animate.css代码

文档

JS实现定位式导航栏

JS实现定位式导航栏:这次给大家带来JS实现定位式导航栏,JS实现定位式导航栏的注意事项有哪些,下面就是实战案例,一起来看一下。完整代码如下:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <s
推荐度:
标签: 定位 导航 菜单
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top