濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > HTML+Sass實(shí)現(xiàn)HambergurMenu(漢堡包式菜單)

HTML+Sass實(shí)現(xiàn)HambergurMenu(漢堡包式菜單)

熱門標(biāo)簽:重慶人工智能電銷機(jī)器人報(bào)價(jià) 愛巢地圖標(biāo)注 長春極信防封電銷卡公司 crm外呼系統(tǒng)好不好 電銷外呼線路改不外呼線路 貴陽ai外呼系統(tǒng) 強(qiáng)訊外呼系統(tǒng) 電話機(jī)器人批發(fā) 智能電銷機(jī)器人廣告語

前幾天看了國外一個(gè)大佬用HTML+CSS實(shí)現(xiàn)HamburgerMenu的視頻,然后最近在看Sass,所以用Sass來實(shí)現(xiàn)一下。

最終效果圖如下:

在VS Code中的文件結(jié)構(gòu)(編譯scss文件用的是easy sass):

頁面結(jié)構(gòu)(index.html):

_config.scss:

/*設(shè)置顏色及max-width*/
$primary-color: rgba(13,110,139,.75);
$overlay-color: rgba(24,39,51,.85);
$max-width: 980px;

/*設(shè)置文本顏色,如果背景色淺,則設(shè)置為黑色,否則設(shè)置為白色*/
@function set-text-color($color){
  @if(lightness($color)>70){
    @return #333;
  }@else{
    @return #fff;
  }
}

/*混合器,設(shè)置背景色及文本顏色*/
@mixin set-background($color){
  background-color: $color;
  color: set-text-color($color);
}

style.scss:

@import '_config';
*{
  margin: 0;
  padding: 0;
}

.container{
  max-width: $max-width;
  margin: 0 auto;
}

/*給showcase設(shè)置背景顏色,利用偽類再添加一個(gè)背景圖,同時(shí)將背景圖的z-index設(shè)置為-1(這樣圖片會(huì)顯示在里面);
然后為了讓文字顯示在中間,所以使用flex布局*/
.showcase{
  position: relative;
  height: 100vh;
  background-color: $primary-color;
  &:before{
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: url('../img/pexels-photo-533923.jpeg') no-repeat center center / cover;
    z-index: -1;
  }
  &-inner{
    display: flex;
    height: 100%;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #fff;
    font-weight: 100;
    h1{
      font-size: 4rem;
      padding: 1.2rem 0;
    }
    p{
      white-space: pre-wrap;
      font-size: 1.6rem;
      padding: 0.85rem 0;
    }
    .btn{
      padding: .65rem 1rem;
        /*使用混合器設(shè)置背景色及文本顏色*/
      @include set-background(lighten($primary-color,30%));
      border: none;
      border: 1px solid $primary-color;
      border-radius: 5px;
      text-decoration: none;
      outline: none;
      transition: all .2s ease .1s;
        /*按鈕hover的時(shí)候利用css3的scale設(shè)置一個(gè)縮放效果*/
      &:hover{
        @include set-background(lighten($overlay-color,30%));
        border-color: lighten($overlay-color, 25%);
        transform: scale(.98);
      }
    }
  }
}

/*原理:通過checkbox的點(diǎn)中與否來進(jìn)行樣式的變化(將checkbox透明度設(shè)置為0,z-index設(shè)置更高),單擊時(shí),會(huì)出現(xiàn)菜單,再次點(diǎn)擊,菜單消失*/
/*給menu-wrap設(shè)置fixed,這樣showcase就會(huì)占滿整個(gè)屏幕;同時(shí)將checkbox的opacity設(shè)置為0;
另外注意,需要將checkbox的z-index設(shè)置為2,因?yàn)閔amburger的z-index設(shè)置為1,不然會(huì)點(diǎn)擊不起作用
*/
.menu-wrap{
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1;
  .toggle{
    position: absolute;
    left: 0;
    top: 0;
    width: 50px;
    height: 50px;
    opacity: 0;
    z-index: 2;
    cursor: pointer;
      /*當(dāng)checkbox為checked時(shí),設(shè)置hamburger里面的div及偽類的旋轉(zhuǎn)效果*/
    &:checked ~ .hamburger>div{
      transform: rotate(135deg);
        /*偽類實(shí)際上旋轉(zhuǎn)了225度,需要將top設(shè)置為0,不然形成的❌長短不一致*/
      &:before,&:after{
        transform: rotate(90deg);
        top: 0;
      }
    }

      /*當(dāng)checkbox選中時(shí)再hover,也會(huì)設(shè)置一個(gè)旋轉(zhuǎn)效果*/
    &:checked:hover ~ .hamburger>div{
      transform: rotate(235deg);
    }
    &:checked ~ .menu{
      visibility: visible;
      >div{
        transform: scale(1);
        >div{
          opacity: 1;
        }
      }
    }
  }
    
  .hamburger{
    position: absolute;
    left: 0;
    top: 0;
    width: 60px;
    height: 60px;
    padding: 1rem;
    background-color: $primary-color;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 1;
      /*div自身生成中間的橫線,然后設(shè)置定位為relative,后面再將其偽類設(shè)置為absolute,
      相對(duì)于div進(jìn)行偏移*/
    >div{
      position: relative;
      left: 0;
      top: 0;
      width: 100%;
      height: 2px;
      background-color: #fff;
      transition: all .7s ease;
        /*利用偽類生成第一條和第三條橫線*/
      &:before,
      &:after{
        content: '';
        position: absolute;
        left: 0;
        top: -10px;
        width: 100%;
        height: 2px;
        background-color: inherit;
      }
      &:after{
        top: 10px;
      }
    }
  }

    /*設(shè)置選中后的菜單的樣式*/
    /*將menu設(shè)置為fixed,同時(shí)寬高為100%,然后設(shè)置display為flex,否則菜單不會(huì)出現(xiàn)在中間*/
  .menu{
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    visibility: hidden;    /*將菜單設(shè)置為不可見,然后在checkbox選中時(shí)設(shè)置為可見*/
    transition: all .75s ease;
    >div{
      @include set-background($overlay-color);
      width: 200vw;
      height: 200vh;
      overflow: hidden;
      border-radius: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
      transform: scale(0);
      transition: all .4s ease;
      >div{
        max-width: 90vw;
        max-height: 90vh;
        opacity: 0;
        transition: all .4s ease;
        >ul>li{
          list-style: none;
          font-size: 2rem;
          padding: .85rem 0;
          text-transform: uppercase;
          transform: skew(-5deg,-5deg) rotate(5deg);/*設(shè)置文字傾斜*/
          a{
            color: inherit;
            text-decoration: none;
            transition: color .4s ease;
          }
        }
      }
    }
  }
}

到此這篇關(guān)于HTML+Sass實(shí)現(xiàn)HambergurMenu(漢堡包式菜單)的文章就介紹到這了,更多相關(guān)HTML+Sass實(shí)現(xiàn)HambergurMenu內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!

標(biāo)簽:吳忠 保定 山南 清遠(yuǎn) 陜西 內(nèi)蒙古 廣安 上海

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML+Sass實(shí)現(xiàn)HambergurMenu(漢堡包式菜單)》,本文關(guān)鍵詞  HTML+Sass,實(shí)現(xiàn),HambergurMenu,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《HTML+Sass實(shí)現(xiàn)HambergurMenu(漢堡包式菜單)》相關(guān)的同類信息!
  • 本頁收集關(guān)于HTML+Sass實(shí)現(xiàn)HambergurMenu(漢堡包式菜單)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    和政县| 新源县| 靖江市| 延川县| 子洲县| 丹凤县| 布尔津县| 集安市| 西和县| 大化| 郑州市| 吉林省| 普格县| 石台县| 澎湖县| 饶阳县| 罗源县| 旬阳县| 法库县| 东方市| 平安县| 绥中县| 砀山县| 苍南县| 齐河县| 阳谷县| 分宜县| 浙江省| 漯河市| 泗洪县| 高雄县| 林周县| 孝昌县| 丰城市| 静海县| 城口县| 呼玛县| 察雅县| 鹰潭市| 宁晋县| 梓潼县|