国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue.js 實現點擊展開收起動畫效果

2019-11-19 13:32:08
字體:
來源:轉載
供稿:網友

最近公司項目加了個頁面,其中要求是這樣的,點擊對應列表,展開和收起,其實就是顯示和隱藏內容部分;說來慚愧,我花了半天時間才搞出來(自黑一下~),接下來分享給大家,先上效果圖:

vue頁面:

<template>  <div class="dealRecord-wrap">    <div class="title-contant" v-for="(item,index) in items " >      <div class="title" @click="showHide(index)">        <h3>2018年0{{index+6}}月</h3>        <div class="number">800筆<i></i></div>      </div>      <div class="contant">        <ul>          <li v-for="i in item.allNumber">            {{index+6}}          </li>        </ul>      </div>    </div>  </div></template><script>export default{  data(){    return{      items:[        {v:'qqq',allNumber:1},        {v:'aaa',allNumber:2},        {v:'qqq',allNumber:3},      ],    }  },  created(){    document.body.style.backgroundColor = '#f6f6f6';  },  mounted(){    for(var i=0;i<3;i++){  //這里取值自后臺返回的長度,設置頁面渲染完成后是否展開,此處不展開      document.getElementsByClassName('contant')[i].style.height = '0px';    }  },  components:{  },  methods:{    showHide(index){  //點擊展開收起      let contant = document.getElementsByClassName('contant')[index];  //這里我們通過參數index來讓瀏覽器判斷你點擊的是哪一個列表        let height = contant.getBoundingClientRect().height;  //獲取頁面元素的當前高度      document.getElementsByTagName('i')[index].style.transform = !!height?'rotateX(0deg)':'rotateX(180deg)';      if (!!height) {      contant.style.height = height + 'px';      let f = document.body.offsetHeight; //強制相應dom重繪,使最新的樣式得到應用      contant.style.height = '0px';      } else {      contant.style.height = 'auto';      height = contant.getBoundingClientRect().height;      contant.style.height = '0';      let f = document.body.offsetHeight;      contant.style.height = height + 'px';      }    }  },  beforeDestroy(){    document.body.style.backgroundColor = '#fff';  }}</script><style type="text/scss" lang="scss" scoped>.dealRecord-wrap{margin-bottom: 100px;  .title-contant{overflow: hidden;  /* 這個是重點 */    .title{height: 84px;padding: 0 24px;border-bottom: 1px solid #eaeaea;/*px*/      h3{height: 84px;font-size: 28px;color: #333;display: flex;align-items: center;float: left;;margin-left: 10px;}      .number{height: 84px;font-size: 24px;color: #666;display: flex;align-items: center;float: right;}      .number i{display: inline-block;width: 23px;height: 13px;background: url('../../assets/images/icon_dropup@2x.png');background-repeat: no-repeat;background-size: 23px 13px;background-position: right 6px center;padding-right: 35px;display: flex;align-items: center; float: right;transform:rotateX(0deg);}    }    .contant{background: #fff;transition: height 1s;  /* 這個也是重點 */      ul li{padding: 0 24px;height: 142px;display: flex;align-items: center;}      ul li:not(:last-child){border-bottom: 1px solid #f6f6f6;/*px*/}    }  }}</style> 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 卓尼县| 固阳县| 缙云县| 新平| 融水| 平罗县| 资兴市| 台前县| 清涧县| 渭南市| 大埔县| 随州市| 咸宁市| 西昌市| 固阳县| 苏尼特左旗| 涿州市| 琼中| 奉节县| 秦安县| 板桥市| 正宁县| 秦皇岛市| 堆龙德庆县| 康定县| 云梦县| 永平县| 衡阳县| 平度市| 遵义县| 天长市| 蒲城县| 大英县| 河北区| 无为县| 汽车| 陆丰市| 吉木乃县| 合江县| 巨鹿县| 邵东县|