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

首頁 > 編程 > JavaScript > 正文

vue移動端實現紅包雨效果

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

本文實例為大家分享了vue實現紅包雨效果的具體代碼,供大家參考,具體內容如下

下面是代碼:

<template>  <div class="ser_home">    <ul class="red_packet" id="red_packet">      <template v-for="(item, index) in liParams">        <li :style="{ left: item.left, animationDuration: item.durTime, webkitAnimationDuration: item.durTime}"  :class="item.cls" :data-index="index" @webkitAnimationEnd="removeDom">          <a href='javascript:;'>            <i :style="{ transform: item.transforms, webkitTransform: item.transforms}"></i>          </a>        </li>      </template>    </ul>  </div></template><script>export default {  data () {    return {      liParams: [],      timer: null,      duration: 10000 // 定義時間    }  },  mounted () {    this.startRedPacket()  },  methods: {    /**     * 開啟動畫     */    startRedPacket() {      let win = document.documentElement.clientWidth || document.body.clientWidth      let left = parseInt(Math.random() * (win - 50) + 0);            let rotate = (parseInt(Math.random() * (45 - (-45)) - 45)) + "deg"; // 旋轉角度      let scales = (Math.random() * (12 - 8 + 1) + 8) * 0.1; // 圖片尺寸      let durTime = (Math.random() * (2.5 - 1.2 + 1) + 1.2) + 's'; // 時間 1.2和1.2這個數值保持一樣      console.log(durTime)      this.liParams.push({left: left+'px', cls: 'move_1', transforms: 'rotate('+ rotate +') scale('+ scales +')', durTime: durTime})      setTimeout( () => {  // 多少時間結束        clearTimeout(this.timer)        return;      }, this.duration)      this.timer = setTimeout( () => {        this.startRedPacket()      },100)      },    /**     * 回收dom節點     */    removeDom (e) {      let target = e.currentTarget;      document.querySelector('#red_packet').removeChild(target)    }  }}</script><!-- Add "scoped" attribute to limit CSS to this component only --><style scoped lang="scss">.ser_home {  width: 100%;  height: 100%;}.red_packet {  display: block;  position: relative;  overflow: hidden;  width: 100%;  height: 100%;  i {    width: 48px;    height: 69px;    display: block;    background: url('/hongbao.png') no-repeat;  }  li {    position: absolute;    animation: all 3s linear;    top:-100px;    z-index: 10;    &.move_1 {      -webkit-animation: aim_move 5s linear 1 forwards;      animation: aim_move 5s linear 1 forwards;    }  }  a {    display: block;  }}@keyframes aim_move {   0% {    -webkit-transform: translateY(0);    transform: translateY(0);   }   100% {    -webkit-transform: translateY(120vh);    transform: translateY(120vh);   }  }</style>

效果圖:

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望奎县| 济阳县| 沧州市| 普兰县| 当雄县| 彰化市| 辉南县| 松滋市| 桐庐县| 宜丰县| 毕节市| 许昌县| 河间市| 达尔| 玉山县| 张北县| 连平县| 曲沃县| 交口县| 轮台县| 万安县| 鲁山县| 铁岭市| 东台市| 岐山县| 长顺县| 秦皇岛市| 邵东县| 新乡市| 瓮安县| 黄大仙区| 密云县| 澎湖县| 安阳市| 雷波县| 温州市| 屏东市| 海盐县| 苗栗县| 舟曲县| 昆山市|