サイドナビゲーションスタイル

図の効果に示すように、ページの左メニューは、固定されていることを確認。

注意事項:最初の面取り右上、赤い背景間隔。使用するCSS知識の必要性:セレクタ、固定位置、線形勾配()関数

 HTML:

< divのクラス= "メニュー" > 
    < ulのクラス= "メニューラップ" > 
        < クラス= "メニュー項目" データ-NAV = "その2" >菜单1 </ > 
        < クラス= "メニュー項目" データNAV = "その3" >菜单2 </ > 
        < リチウムのクラス= "メニュー項目" データNAV = "その4" >菜单3 </ > 
        <クラス=「メニュー項目」データ-NAV =「その5」>菜单4 </ > 
        < リチウムのクラス= "メニュー項目" データNAV = "その6" >菜单5 </ > 
        < リチウムのクラス= "メニュー項目" データNAV = "その1" > TOP < EM > </ EM > </ > 
    </ UL > 
</ DIV >

 

 < DIV クラス= "その1" > 
 </ DIV > 
 < DIV クラス= "その2" > 
 </ DIV > 
 < DIV クラス= "その3" > 
 </ DIV > 
 < DIV クラス= "その4" > 
 </ DIV > 
 < DIV クラス= "その5" > 
 </ divの> 
 < divのクラス= "その6" > 
 </ DIV >

 

这里用的scss语法,高亮有些不对哦:

.menu {
  position: fixed;
  top: 23%;
  left: 0;
  width: 14.5%;
  z-index: 1;
  .menu-wrap {
    font-size: 1em\0;
    font-weight: bold;
    text-align: center;
    letter-spacing: 0.1rem;
    .menu-item {
      font-size: 1rem;
      width: 100%;
      height: 2.5em/0;
      height: 2.5rem;
      line-height: 2.5em/0;
      line-height: 2.5rem;
      cursor: pointer;
      color: black;
      &:nth-child(odd) {
        background-color: #f5f5f7;
      }
      &:nth-child(even) {
        background-color: #cb263d;
        color: white;
      }
      &:first-child {
        background: linear-gradient(-138deg, transparent 14px, #f5f5f7 0) right, linear-gradient(90deg, transparent 0px, #f5f5f7 0) left;
        background-size: 51% 100%;
        background-repeat: no-repeat;
        letter-spacing: -0.05rem;
        em {
          display: inline-block;
          width: 9%;
          height: 2.9rem;
          background: #f3e7c7;
          position: absolute;
          left: 0;
        }
      }
      &:last-child {
        background-color: #434444;
        color: #d64833;
        em {
          display: inline-block;
          border-left: 6px solid transparent;
          border-right: 6px solid transparent;
          border-bottom: 10px solid #5ac3e2;
        }
      }
    }
  }
}
background: linear-gradient(-138deg, transparent 14px, #f5f5f7 0) right, linear-gradient(90deg, transparent 0px, #f5f5f7 0) left;   把right和left顺序交换也是一样的
拆解:

js:

 

 1 !(function ($) {
 2     var Common = Common || {};
 3     
 4     // 菜单导航跳转 参数:ul=>".menu-wrap"
 5     Common.MenuNav = function (menuwrap, flag) {
 6         if (!!!menuwrap) {
 7             menuwrap = '.menu-wrap'
 8         }
 9         $(menuwrap).on('click', 'li', function () {
10             var visibleH = window.innerHeight || document.body.clientHeight;
11             var scrollH = $(window).scrollTop();
12             var _this = $("." + $(this).attr("data-nav"));
13             var targetTop = _this.offset().top;
14             $('html, body').animate({
15                 scrollTop: targetTop - 40
16             }, 500);
17         })
18     }
19     $.Common = Common
20 })(jQuery)
21 
22 $.Common.MenuNav()

 

 

 

おすすめ

転載: www.cnblogs.com/cyhan/p/11926517.html