jquery如何实现滑动楼梯效果

发布时间:2021-09-24 10:50:02 作者:小新
来源:亿速云 阅读:106

小编给大家分享一下jquery如何实现滑动楼梯效果,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

思路:鼠标滚动的时候页面跟随变化,点击模块时候,实现指哪打哪效果

代码的实现

1.html和css代码

<html>
 <head>
  <meta charset="UTF-8">
  <title></title>
  <style type="text/css">
   body,ul,li{
    padding: 0;
    margin: 0;
   }
   li{
    list-style: none;
   }
   #floorNav{
    display: none;
    position: fixed;
    top: 100px;
    left: 50px;
    width: 32px;
    border: 1px solid #CECECE;
   }
   #floorNav li{
    position: relative;
    width: 32px;
    height: 32px;
    border-bottom: 1px solid #CECECE;
    text-align: center;
    line-height: 32px;
    font-size: 12px;
   }
   
   #floorNav span{
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 32px;
    height: 32px;
    background: red;
    color: white;
   }
   
   #floorNav li:hover span,#floorNav li.hover span{
    display: block;
   }
   
   #floorNav li:last-child{
    background: red;
    color: white;
    border-bottom: none;
   }
   #header,#footer{
    width: 1000px;
    height: 1000px;
    background: darkgoldenrod;
    margin: 0 auto;
   }
   #content{
    
   }
   #content li{
    width:1000px;
    height: 600px;
    margin: 0 auto;
    font-size: 40px;
    text-align: center;
    line-height: 600px;
   }
  </style>
 </head>

 <body>
  <div id="floorNav">
   <ul>
    <li>1F<span>服饰</span></li>
    <li>2F<span>美妆</span></li>
    <li>3F<span>手机</span></li>
    <li>4F<span>家电</span></li>
    <li>5F<span>数码</span></li>
    <li>6F<span>运动</span></li>
    <li>7F<span>居家</span></li>
    <li>8F<span>母婴</span></li>
    <li>9F<span>食品</span></li>
    <li>10F<span>图书</span></li>
    <li>11F<span>服务</span></li>
    <li>TOP</li>
   </ul>
  </div>
  <div id="header"></div>
  <div id="content">
   <ul>
    <li >服饰</li>
    <li >美妆</li>
    <li >手机</li>
    <li >家电</li>
    <li >数码</li>
    <li >运动</li>
    <li >居家</li>
    <li >母婴</li>
    <li >食品</li>
    <li >图书</li>
    <li >服务</li>
   </ul>
 </div>
 <div id="footer"></div>
</body>

2.接下来进行引入一个 jQuery 文件然后进行jQuery代码的编写

<script>
    $(function(){

 //定义判别
 var flag = true
 
  $(window).scroll(function(){

   if(flag){
   //显示隐藏的楼梯
   var scrollTop=$(this).scrollTop();
   if(scrollTop>=500){
    $("#floorNav").fadeIn()
   } else{
    $("#floorNav").fadeOut();
   }

   //指哪打哪
   $("#content li").each(function(){
    if(scrollTop>=$(this).offset().top-$(this).outerHeight()/2){
     var index = $(this).index();
     $("#floorNav li").eq(index).addClass("hover")
     .siblings().removeClass("hover")
    }

   })
   }
  })
 
  //点击的时候滚动条滚动到相应的位置
  $("#floorNav li:not(:last)").click(function(){
   flag=false
   var index = $(this).index();
   $("html ,body").animate({"scrollTop":$("#content li").eq(index).offset().top},500)
  
   flag=true
   $(this).addClass("hover").siblings().removeClass("hover")
  })
 
   $("#floorNav li:last").click(function(){
    flag = false;
    $("html,body").animate({"scrollTop":0},200,function(){
     flag = true
    })
   })
 })

</script>

看完了这篇文章,相信你对“jquery如何实现滑动楼梯效果”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. jQuery实现楼梯效果
  2. jQuery滑动星星评分效果

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

jquery

上一篇:go语言如何实现yaml转map、map遍历

下一篇:js如何实现楼层滚动效果

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》