jquery达成左侧栏菜单采纳操作,基于Jquery完成仿

作者: 关于计算机  发布:2019-09-03

先给大家展现下效果图,看看是或不是亲想要达成的成效,假如还满足的话请查看本文详细情况,同一时间我们也足以下载源码哦。

jquery完成侧面栏菜单选拔操作,jquery左边栏菜单

正文实例分享了jquery落成侧边栏菜单接纳的相关代码,供大家参照他事他说加以考察,具体内容如下

效果图:

图片 1

落实菜单:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>右侧栏菜单</title>
  <style type="text/css">
      *{
      margin: 0;
      padding: 0;
      }
      .wrap{
      width: 500px;
      }
      .block{
       border:1px solid #ccc;
       margin: 20px 20px;
      }
      .rightMenu{
       position: fixed;
       right: 50px;
       top: 200px;
       /*opacity: 0;*/
       display: none;
      }
      .rightMenu li{
        list-style: none;
        display: block;
        width: 80px;
        height: 32px;
        line-height: 32px;
        text-align: center;
        border: 1px solid blue;
        margin: 5px 0px;

      }
      .rightMenu li a{
        text-decoration: none;
        color: black;

      }
  </style>
</head>
<body>
   <div class="wrap">
     <div class="block block1">
        <h4>第一部分</h4>
        <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
        </p>
     </div>
     <div class="block block2">
        <h4>第二部分</h4>
        <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
        </p>
     </div>
     <div class="block block3">
        <h4>第三部分</h4>
        <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
        </p>
     </div>
     <div class="block block4">
        <h4>第四部分</h4>
        <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab ea labore, doloremque eaque veritatis consectetur distinctio ipsam, perferendis cum expedita assumenda minus! Magnam itaque dolorum dignissimos, ullam asperiores! Deleniti, rem?
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia porro assumenda voluptas exercitationem velit architecto nobis id odit ullam ut ex minima earum expedita distinctio nam culpa, harum, error veniam!
        </p>
     </div>

   </div>
   <ul class="rightMenu">
          <li><a href="###">第一部分</a></li>
          <li><a href="###">第二部分</a></li>
          <li><a href="###">第三部分</a></li>
          <li><a href="###">第四部分</a></li>
     </ul>
   <script type="text/javascript" src="jquery-1.11.3.min.js"></script>
   <script type="text/javascript">
    $(function(){
       $(".rightMenu").on("click","li",function(){
         // alert($(this).index())
         var index = $(this).index();
         console.log(index);
         var t = $(".wrap .block").eq(index).offset().top
         $("html body").animate({
           scrollTop:t
         })
       })
       var h = $(".rightMenu").height();
      $(window).scroll(function(){
         if($(document).scrollTop()<200){
          // alert("kk");
          $(".rightMenu").stop().animate({
             height:0,
               opacity: 0

          },1000)
         }
         else{
          $(".rightMenu").show().stop().animate({
               height:h,
               opacity: 1

          },1000)
         }
      })


    })
   </script>
</body>
</html>

上述正是本文的全体内容,希望对大家的读书抱有援助。

效果图:

您或者感兴趣的文章:

  • jquery插件达成鼠标经过图片左边展现大图的功用(类似天猫)
  • JQuery右键菜单插件ContextMenu使用指南
  • jQuery 实现左边浮动导航菜单功用
  • jQuery插件PageSlide实现左侧边栏导航菜单
  • jquery达成转移的侧栏实例
  • jquery实现鼠标滑过展现二级下拉菜单效果
  • jquery达成左右滑动菜单功用代码
  • 基于Jquery达成仿百度百科左边导航代码附源码下载

本文实例分享了jquery完成右边栏菜单选择的连带代码,供大家参照他事他说加以考察,具体内容如下 效果图...

图片 2

效果体现    源码下载.rar)

代码表明:

仿百度百科侧边导航代码jquery插件,那几个仿百科侧边导航js代码,在比较久从前就疑似搞个用了,因为这些导航特别符合长篇文档使用,花了半天时间写了那个仿百科导航插件,然而和百度百小飞侠起来仍旧有一些弱,没有实现侧边导航区域滚动的机能,假设您的文书档案不是一流变态长,应该充足。

只要您的领航拔尖长,可能要用到左边导航页能够滚动,一般景况下还是用不到,等过些时候有好的实现思路再搞吧,方今没悟出完毕右边导航区域和左边内容的轮转何况联合浮动的好方法。

专一:var directoryNav = new DirectoryNav($("h2,h3"),{}); 中的"h2,h3"便是生成两级导航的内容节点

/*
 *仿百度百科右侧导航代码 - 页面目录结构导航 v0.01
 * 只写了两级,无限级别也可以,是逻辑上的级别,html结构全是同一级别
 * 滑标动画用的css3过渡动画,不支持的浏览器就没动画效果了
 * 和百度百科比起来还是比较弱,没有实现右边也可以滚动的功能
 */
 function DirectoryNav($h,config){
  this.opts = $.extend(true,{
   scrollThreshold:0.5, //滚动检测阀值 0.5在浏览器窗口中间部位
   scrollSpeed:700,  //滚动到指定位置的动画时间
   scrollTopBorder:500, //滚动条距离顶部多少的时候显示导航
   easing: 'swing',  //不解释
   delayDetection:200,  //延时检测,避免滚动的时候检测过于频繁
   scrollChange:function(){}
  },config);
  this.$win = $(window);
  this.$h = $h;
  this.$pageNavList = "";
  this.$pageNavListLis ="";
  this.$curTag = "";
  this.$pageNavListLiH = "";
  this.offArr = [];
  this.curIndex = 0;
  this.scrollIng = false;
  this.init();
 }
 DirectoryNav.prototype = {
  init:function(){
   this.make();
   this.setArr();
   this.bindEvent();
  },
  make:function(){
   //生成导航目录结构,这是根据需求自己生成的。如果你直接在页面中输出一个结构那也挺好不用 搞js
   $("body").append('<div class="directory-nav" id="directoryNav"><ul></ul></div>>');
   var $hs = this.$h,
    $directoryNav = $("#directoryNav"),
    temp = [],
    index1 = 0,
    index2 = 0;
   $hs.each(function(index){
    var $this = $(this),
      text = $this.text();
    if(this.tagName.toLowerCase()=='h2'){
     index1++;
     if(index1%2==0) index2 = 0;
     temp.push('<li class="l1">'+index1+'. <a class="l1-text">'+text+'</a></li>');
    }else{
     index2++;
     temp.push('<li class="l2">'+index1+'.'+index2+' <a class="l2-text">'+text+'</a></li>');
    }
   });
   $directoryNav.find("ul").html(temp.join(""));
   //设置变量
   this.$pageNavList = $directoryNav;
   this.$pageNavListLis = this.$pageNavList.find("li");
   this.$curTag = this.$pageNavList.find(".cur-tag");
   this.$pageNavListLiH = this.$pageNavListLis.eq(0).height();
   if(!this.opts.scrollTopBorder){
    this.$pageNavList.show();
   }
  },
  setArr:function(){
   var This = this;
   this.$h.each(function(){
    var $this = $(this),
     offT = Math.round($this.offset().top);
    This.offArr.push(offT);
   });
  },
  posTag:function(top){
   this.$curTag.css({top:top+'px'});
  },
  ifPos:function(st){
   var offArr = this.offArr;
   //console.log(st);
   var windowHeight = Math.round(this.$win.height() * this.opts.scrollThreshold);
   for(var i=0;i<offArr.length;i++){
    if((offArr[i] - windowHeight) < st) {
     var $curLi = this.$pageNavListLis.eq(i),
      tagTop = $curLi.position().top;
     $curLi.addClass("cur").siblings("li").removeClass("cur");
     this.curIndex = i;
     this.posTag(tagTop+this.$pageNavListLiH*0.5);
     //this.curIndex = this.$pageNavListLis.filter(".cur").index();
     this.opts.scrollChange.call(this);
    }
   }
  },
  bindEvent:function(){
   var This = this,
    show = false,
    timer = 0;
   this.$win.on("scroll",function(){
    var $this = $(this);
    clearTimeout(timer);
    timer = setTimeout(function(){
     This.scrollIng = true;
     if($this.scrollTop()>This.opts.scrollTopBorder){
      if(!This.$pageNavListLiH) This.$pageNavListLiH = This.$pageNavListLis.eq(0).height();
      if(!show){
       This.$pageNavList.fadeIn();
       show = true;
      }
      This.ifPos( $(this).scrollTop() );
     }else{
      if(show){
       This.$pageNavList.fadeOut();
       show = false;
      }
     }
    },This.opts.delayDetection);
   });
   this.$pageNavList.on("click","li",function(){
    var $this = $(this),
     index = $this.index();
    This.scrollTo(This.offArr[index]);
   })
  },
  scrollTo: function(offset,callback) {
   var This = this;
   $('html,body').animate({
    scrollTop: offset
   }, this.opts.scrollSpeed, this.opts.easing, function(){
    This.scrollIng = false;
    //修正弹两次回调 蛋疼
    callback && this.tagName.toLowerCase()=='body' && callback();
   });
  }
 };
 //调用实例化
 var directoryNav = new DirectoryNav($("h2,h3"),{
  scrollTopBorder:0 //滚动条距离顶部多少的时候显示导航,如果为0,则一直显示
 });

在写百度百科左边导航js代码的时候有个主张,正是让侧边导航区域的滚动条和右边内容的滚动条用三个总结公式让他们关系起来,完成同台滚动。

您恐怕感兴趣的篇章:

  • jquery插件落成鼠标经过图片右边展现大图的意义(类似Taobao)
  • JQuery右键菜单插件ContextMenu使用指南
  • jQuery 达成左侧浮动导航菜单成效
  • jQuery插件PageSlide达成左侧面栏导航菜单
  • jquery完结转移的侧栏实例
  • jquery完毕鼠标滑过显示二级下拉菜单效果
  • jquery达成左右滑动菜单成效代码
  • jquery完毕左边栏菜单选用操作

本文由王中王开奖结果发布于关于计算机,转载请注明出处:jquery达成左侧栏菜单采纳操作,基于Jquery完成仿

关键词:

上一篇:jQuery插件EasyUI校验规则
下一篇:没有了