<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      不定高元素動畫實現(xiàn)方案(上)

      前情

      最近接了一個需求,需要實現(xiàn)一個列表,列表可展開收起,展開收起需要有一個動畫效果,而列表個數(shù)不定且每項內(nèi)容高度也不固定,所以是一個不定高的收起展開效果,我嘗試了如下幾中方式,最后選擇了我覺得最佳的

      通過max-height來實現(xiàn)

      其實把高度設(shè)為auto,可以讓元素高度撐開,但是auto是不會有動畫效果的,此時我們可以把max-height設(shè)為一個較大的值,這樣就實現(xiàn)動畫效果了

      代碼如下:

      <!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>JS Bin</title>
      </head>
      <body>
        <div class="container">
          <div class="inner">
            <div class="header">header</div>
            <ul class="list">
              <li>111111111</li>
              <li>2222222222</li>
              <li>333333333</li>
            </ul>
          </div>
        </div>
      </body>
      </html>
      
      *{
        margin: 0;
        padding: 0;
      }
      .container{
        width: 100%;
        max-height: 48px;
        overflow: hidden;
        transition:max-height .4s;
      }
      .container:hover{
        max-height: 111px;
      }
      .header{
        width: 100%;
        height: 48px;
        background-color: #ccc;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .list{
        background-color: green;
      }
      

      演示地址:https://jsbin.com/cedifocuci/edit?html,css,output

      20250920_140623

      注意:

      max-height設(shè)的太高動畫效果會太快,設(shè)的太小又無法適配所有高度,此方案只能說是能解決問題,但是不是最理想的方案

      通過Grid布局來實現(xiàn)

      通過網(wǎng)絡(luò)布局,一開始設(shè)置grid-template-rows為0fr,這里有一些技巧,如果子元素有內(nèi)容,0fr是不生效的,要給子元素設(shè)置min-height為0;如果初始要有基礎(chǔ)高度,可以設(shè)置min-height為指定高度來實現(xiàn)基礎(chǔ)高度,此處為48px

      關(guān)鍵代碼如下:

      <!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>JS Bin</title>
      </head>
      <body>
        <div class="container">
          <div class="inner">
            <div class="header">header</div>
            <ul class="list">
              <li>Grid111111111</li>
              <li>Grid2222222222</li>
              <li>Grid333333333</li>
              <li>Grid444444444</li>
            </ul>
          </div>
        </div>
      </body>
      </html>
      
      *{
        margin: 0;
        padding: 0;
      }
      .container{
        width: 100%;
        display: grid;
        grid-template-rows: 0fr;
        min-height: 48px;
        overflow: hidden;
        transition:all .4s;
      }
      .inner{
        min-height: 0;
      }
      .container:hover{
        grid-template-rows: 1fr;
      }
      .header{
        width: 100%;
        height: 48px;
        background-color: #ccc;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .list{
        background-color: green;
      }
      

      演示地址:https://jsbin.com/xasuviputo/edit?html,css,output

      20250920_145048

      注意:

      主流瀏覽器都支持,但是部分國內(nèi)瀏覽器還是有很大兼容問題,如果對兼容性有很高要求的話此方案就不合適了,同時如果你有基礎(chǔ)高度,那基礎(chǔ)高度的那一段是沒有動畫效果的

      image

      通過clip-path來實現(xiàn)

      clip-path又叫CSS裁剪路徑,clip-path 屬性用于創(chuàng)建一個元素的可視區(qū)域,區(qū)域內(nèi)的內(nèi)容會顯示,而區(qū)域外的內(nèi)容則會被隱藏。這個屬性可以用來對元素進行形狀裁剪,實現(xiàn)各種視覺效果
      此處使用clip-path:inset()來實現(xiàn),可以傳入四個數(shù)字inset(1 2 3 4),它們的規(guī)則如下圖

      PixPin_2025-09-20_16-10-01

      關(guān)鍵代碼如下:

      <!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>JS Bin</title>
      </head>
      <body>
        <div class="container">
          <div class="inner">
            <div class="header">header</div>
            <ul class="list">
              <li>clip-path111111111</li>
              <li>clip-path2222222222</li>
              <li>clip-path333333333</li>
              <li>clip-path444444444</li>
            </ul>
          </div>
        </div>
      </body>
      </html>
      
      *{
        margin: 0;
        padding: 0;
      }
      .container{
        width: 100%;
        clip-path: inset(0 0 calc(100% - 48px) 0);
        overflow: hidden;
        transition:all .4s;
      }
      .container:hover{
        clip-path: inset(0 0 0 0);
      }
      .header{
        width: 100%;
        height: 48px;
        background-color: #ccc;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .list{
        background-color: green;
      }
      

      演示地址:https://jsbin.com/zelopuyuxi/edit?html,css,output

      20250920_155649

      注意:

      主流瀏覽器都支持,但是部分國內(nèi)瀏覽器還是有很大兼容問題,如果對兼容性有很高要求的話此方案就不合適了,相比grid此方案不會有基礎(chǔ)高度無過渡效果的問題

      image 1

      小結(jié)

      對于做技術(shù)的我們,每天都是提出問題解決問題的一個過程,過程中會嘗試各種方案,因為解決問題的方案千千萬,此篇文章記錄了實現(xiàn)不定高內(nèi)容過渡效果的三種實現(xiàn)方式,怕篇幅太長,此文暫時寫這么多,下篇繼續(xù)……

      posted @ 2025-09-20 16:47  !win !  閱讀(97)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 四虎成人在线观看免费| 亚洲成人av在线系列| 18禁免费无码无遮挡不卡网站| 屏山县| 99人中文字幕亚洲区三| 国产激情艳情在线看视频| 国产高清精品在线91| 亚洲色av天天天天天天| 国产精品十八禁在线观看| gogogo高清在线播放免费| 免费无码成人AV片在线| 亚洲性一交一乱一伦视频| 亚洲av无码专区在线亚| 成人免费无遮挡在线播放| 天堂a无码a无线孕交| 日本精品中文字幕在线不卡| 国产日韩一区二区在线| 伊人色综合久久天天| 成人无号精品一区二区三区| 成人无码潮喷在线观看| 亚洲av精选一区二区| 国产在线98福利播放视频| 强奷乱码中文字幕| 婷婷久久香蕉五月综合加勒比| 麻豆人人妻人人妻人人片av| 一区二区三区四区五区自拍| 亚洲天码中文字幕第一页| 亚洲精品久久麻豆蜜桃| 国产激情艳情在线看视频| 国内揄拍国内精品少妇| 99久久久无码国产麻豆| 亚洲成人四虎在线播放| 久激情内射婷内射蜜桃| 国产成人精品亚洲精品密奴| 国产在线播放专区av| 国产精品污www在线观看| 亚洲区激情区无码区日韩区| 亚洲国产日韩一区三区| 国产一区二区不卡91| 日本亚洲欧洲免费无线码| 久久亚洲2019中文字幕|