最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery實現吸頂導航效果

 更新時間:2020年01月08日 09:44:42   作者:c_c_.  
這篇文章主要為大家詳細介紹了jquery實現吸頂導航效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了jquery實現吸頂導航效果的具體代碼,供大家參考,具體內容如下

css:

 *{margin:0;padding:0;}
 body{
 margin:0 auto;
   max-width:10rem;
 }
 header{
 width:10rem;
 height:1rem;
 background:red;
 position:fixed;
 top:0;
 left:auto;
 }
 section{
 height:100%;
 overflow: auto;
 padding:1rem 0;
 }
 .bananers{
 width:100%;
 height:3rem;
 text-align: center;
 line-height:3rem;
 background: aqua;
 }
 .mains{
 width:100%;
 height:1rem;
 background:red;
 display: flex;
 }
 .mains>div{
 width:100%;
 height:100%;
 border:1px solid #dddddd;
 display: flex;
 align-items: center;
 justify-content: center;
 }
 .contents{
 width:100%;
 }
 .contents>div{
 height:50px;
 line-height:50px;
 padding-left:10%;
 border-bottom:1px solid red;
 }
 footer{
 width:10rem;
 height:1rem;
 background: #0086B3;
 position:fixed;
 left:auto;
 bottom:0;
 }
  .fixed-top {
    position: fixed;
    width: 100%;
    top:1rem;
    left:auto;
  }
  .sticky {
    position: -webkit-sticky;/*滾過初始位置時自動吸頂*/
    position: sticky;/*吸頂時的定位*/
    top:1rem;
    left:auto;
    z-index: 999;/*z-index比下方所有層級要高*/
  }

html:

<header>頭部</header>
<section>
  <div class="bananers">內容</div>
  <div class="mains">
  <div>導航1</div>
  <div>導航2</div>
  <div>導航3</div>
  </div>
  <div class="contents"></div>
</section>
<footer>頁腳</footer>

js:

for(var i=0;i<20;i++){
 $(".contents").append(`<div>${i+1}</div>`)
 }
 var headers=$("header")[0].getBoundingClientRect().height;
 var mains=$(".mains").offset().top;
 var heights=mains-headers;
 $(".bananers").html(mains+"----"+headers);
 var tops = document.querySelector('.mains');
 function fixed(num) {
    var nys= navigator.userAgent;
    var isAndroid = nys.indexOf('Android') > -1 || nys.indexOf('Adr') > -1; 
    var isIOS = !!nys.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); 
    if(isAndroid) {
      document.body.onscroll = function(e) {
        var scrollT = document.body.scrollTop;
        if (scrollT > num) {
          $(tops).addClass('fixed-top');
        }else {
          $(tops).removeClass('fixed-top');
        }
      };
    }else if(isIOS) {
      $(tops).addClass('sticky');
    }
  }
fixed(heights);

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

亳州市| 陆河县| 克拉玛依市| 高碑店市| 阿拉尔市| 开平市| 友谊县| 罗江县| 呼玛县| 界首市| 周至县| 清苑县| 防城港市| 福贡县| 铁岭县| 南部县| 贵南县| 宁河县| 尚义县| 东光县| 龙泉市| 高淳县| 游戏| 杭州市| 萨嘎县| 都匀市| 延吉市| 蒙自县| 灌南县| 华亭县| 新田县| 曲周县| 呼和浩特市| 恭城| 木兰县| 闽侯县| 辰溪县| 富源县| 长岭县| 葫芦岛市| 通榆县|