≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > vue.js

vue移动端实现红包雨效果

人气:1667 时间:2019-04-10

这篇文章主要为大家详细介绍了vue移动端实现红包雨效果,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!

本文实例为大家分享了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>

效果图:

【图片暂缺】

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持四海网。

本文来自:http://www.q1010.com/184/5281-0.html

注:关于vue移动端实现红包雨效果的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:vue.js

您可能感兴趣的文章

  • vue-router中scrollBehavior的巧妙用法
  • vue使用监听实现全选反选功能
  • vue中element 上传功能的实现思路
  • vue使用中的内存泄漏【推荐】
  • vue实现动态添加数据滚动条自动滚动到底部的示例代码
  • vue.js内置组件之keep-alive组件使用
  • Vue项目添加动态浏览器头部title的方法
  • vue.js实现格式化时间并每秒更新显示功能示例
  • Vue如何实现响应式系统
  • vue自定义移动端touch事件之点击、滑动、长按事件
上一篇:vue中动态设置meta标签和title标签的方法
下一篇:vue使用中的内存泄漏【推荐】
热门文章
  • Vue 报错TypeError: this.$set is not a function 的解决方法
  • vue实现动态添加数据滚动条自动滚动到底部的示例代码
  • vue项目设置scrollTop不起作用(总结)
  • vue项目中使用vue-i18n报错的解决方法
  • iview实现select tree树形下拉框的示例代码
  • 分析关于element级联选择器数据回显问题
  • vue项目打包后打开页面空白解决办法
  • 解决element ui select下拉框不回显数据问题的解决
  • element-ui table span-method(行合并)的实现代码
  • element-ui 设置菜单栏展开的方法
  • 最新文章
    • 理解vue ssr原理并自己搭建简单的ssr框架
    • vue favicon设置以及动态修改favicon的方法
    • vue-router启用history模式下的开发及非根目录部署方法
    • 从零开始在NPM上发布一个Vue组件的方法步骤
    • Element input树型下拉框的实现代码
    • Vue 报错TypeError: this.$set is not a function 的解决方法
    • Vue.js组件高级特性实例分析
    • 浅谈VueJS SSR 后端绘制内存泄漏的相关解决经验
    • 分析Vue.js自定义tipOnce指令用法实例
    • 浅谈vuex actions和mutation的异曲同工

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。