本文实例为大家分享了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>
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]
- 金池刘罡《昨日情歌HQ》头版限量编号[低速原抓WAV+CUE]
- 段奥娟.2024-23·岁碎念【白米范】【FLAC分轨】
- 顺子.2001-昨日·唯一·更多·顺子自选辑【魔岩】【WAV+CUE】
- 无印良品.1999-私藏三首·原创相对论(EP)【滚石】【WAV+CUE】
- Merryland《Merryland》[FLAC/分轨][170.22MB]
- 庄锭欣 ELKIE《没有你的未来》[320K/MP3][15.78MB]
- 庄锭欣 ELKIE《没有你的未来》[FLAC/分轨][36MB]
- TchaikovskySwanLake,Op.20柴可夫斯基天鹅湖(2013)SACD[Hi-Res]
- 24bit达人艺典《琴歌终极版》整轨WAV+CUE
- 黑鸭子.2005-《发烧DSD》柏菲[WAV分轨]
- 群星.1990-电影看板·人间道【宝丽金】【WAV+CUE】
- 周殷廷.2024-TO.WHOM.IT.MAY.CONCERN【环球】【FLAC分轨】