<div class="test"><...">
最新公告
  • 欢迎您光临起源地模板网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入钻石VIP
  • vue.js实现收能量

    正文概述 掘金(可爱子)   2021-06-21   652

    其他活动实现:

    1.实现的放大的同时上下移动 (先将代码部分抽出现实现)

    vue.js实现收能量

     <!-- <div class="father">
        <div class="test"></div>
        <div class="test"></div>
        <div class="test"></div>
        <div class="test"></div>
      </div> -->
      <div class="father">
        <div class="test"></div>
      </div>
      <div class="father">
        <div class="test"></div>
      </div>
      <div class="father">
        <div class="test"></div>
      </div>
      <div class="father">
        <div class="test"></div>
      </div>
      <style>
         @keyframes father{
          0%   {
            transform: translate(0, 0)
          }
          50%  {
            transform: translate(0, -15px)
          }
          100% {
            transform: translate(0, 0px)
          }
        }
        .father{
          animation: father 1.5s ease-in-out 1s forwards infinite
        }
        .test {
          width: 50px;
          height: 50px;
          background-color: burlywood;
          border-radius: 50%;
          animation: star-stone 1s ease-in-out 0s forwards alternate;
        }
        @keyframes star-stone{
          from{
            transform: scale(0, 0);
          }
          to{
            transform: scale(1, 1);
          }
        }
      </style>
    

    因为泡泡的出现是随机出现的,那么必须保证上下移动的步调是一致的,所以必须将上下移动的css动画放在子元素的父级

    2.实现能量的排版与自动出现

    vue.js实现收能量

    2.1先定义是否显示的option参数,因为import进来的数据,存在引用,所以这里使用工厂函数

    /indexOption.js

    export function imgArrFun () {
      return [
        {
          id: 1,
          isShow: false,
        },
        {
          id: 2,
          isShow: false,
        },
        {
          id: 3,
          isShow: false,
        },
        {
          id: 4,
          isShow: false,
        },
        {
          id: 5,
          isShow: false,
        },
        {
          id: 6,
          isShow: false,
        },
        {
          id: 7,
          isShow: false,
        },
        {
          id: 8,
          isShow: false,
        },
        {
          id: 9,
          isShow: false,
        },
        {
          id: 10,
          isShow: false,
        },
      ]
    }
    export function idArrFun () {
      return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    }
    
    2.2实现

    index.vue

    html:

    <!-- 能量分布 -->
     <span :class="['father', centerVisible ? 'star-energy-center' : 
     `position${index + 1}`]"  v-for="(item, index) in imgList" :key="index">
         <img v-show="item.isShow" :class="[item.isShow ? 'star-stone': '' ]" 
         src="@/assets/image/starEnergy/starStone.png">
     </span>
     
     <!-- 可领取 -->
     <div v-show="!pushVisible && bubbleShow" class="star-energy-button" @click="combine"></div>
    

    css:

       .star-stone {
          width: 100%;
          animation: star-stone 1s ease-in-out 0s forwards alternate;
        }
        @keyframes star-stone{
          from{
            transform: scale(0, 0);
          }
          to{
            transform: scale(1, 1);
          }
        }
        @keyframes father{
          0%   {
            transform: translate(0, 0)
          }
          50%  {
            transform: translate(0, -15px)
          }
          100% {
            transform: translate(0, 0px)
          }
        }
        .position1 {
          top: 48px;
        }
        .position2 {
          top: 178px;
          left: 180px;
        }
        .position3 {
          top: 178px;
        }
        .position4 {
          top: 178px;
          left: 440px;
        }
        .position5 {
          top: 244px;
          left: 570px;
        }
        .position6 {
          top: 244px;
          left: 50px;
        }
        .position7 {
          top: 308px;
          left: 180px;
        }
        .position8 {
          top: 308px;
        }
        .position9 {
          top: 308px;
          left: 440px;
        }
        .position10 {
          top: 438px;
        }
        
        .father{
          @include position(absolute, 130px, 130px);
          left: 310px;
          right: 310px;
          top: 243px;
          animation: father 1.5s ease-in-out 1s forwards infinite
        }
       .star-energy-center{
          position: absolute;
          transition: all 1s linear;
          animation: star-energy-center 2s linear forwards alternate;
        }
        @keyframes star-energy-center {
          0%   {
            transform: translate(0, 0);
            opacity: 1;
          }
          50%   {
            transform: translate(0, 0);
            opacity: 1;
          }
          100% {
            transform: translateY(-200px);
            transition: all .1s;
            opacity: 0;
          }
        }
    

    js部分

      computed: {
        // 没有泡泡就让按钮显示不可以按
        'bubbleShow' () {
          const list = this.imgList.filter(item => item.isShow) || []
          return list.length > 0
        },
      },
      async created () {
        this.imgList = imgArrFun()
        // 首次加载先让能量随机出现
        this.getStarEnergyData()
      },
      
      methods: {
        // 获取星能量倒计时和可领取奖励数
        async getStarEnergyData () {
          this.$loading.show()
          const data = await xxxx接口(this.token)
          this.isCombineVisible = true
          this.starEnergyData = data.info
          // 拿到后台返回的数据
          const energyBouns = 10 * +this.ruleData.wealthBonus
          this.showEnergyNum = this.starEnergyData.accumulateWealthNum >= energyBouns ?
          10 : (+this.starEnergyData.accumulateWealthNum % energyBouns) / 
          this.ruleData.wealthBonus
          this.showStarEnergy(this.showEnergyNum)
          this.surplusTime = +this.starEnergyData.surplusTime
        },
        // 点击合成
        async combine () {
          if (this.isCombineVisible) { // 设置isCombineVisible防止重复点击
            this.pushVisible = true // 因为按下去是其他样式,所以设定一个状态
            setTimeout(async () => {
              this.pushVisible = false
              await getStarEnergyApi(this.token) // 合成的时候需要进行一次上报
              this.isCombineVisible = false
              this.centerVisible = true // 主要是做收能量的动效
              document.getElementsByClassName('father')[0].addEventListener(
              'animationend', this.animationendFunc)
            }, 100)
          }
        },
        // 消失之后,将数据初始化
        animationendFunc () {
          if (!this.centerVisible) {
            return
          }
          this.imgList = imgArrFun()
          this.showBouns = true
          // 2s之后将显示弹框隐藏,居中class隐藏,重新调接口
          setTimeout(() => {
            this.showBouns = false
            this.centerVisible = false
            this.getStarEnergyData()
          }, 2000)
        },
        // 显示能量球以及开始倒计时
        async showStarEnergy (num) {
          clearInterval(this.timer)
          this.countDown(this.surplusTime)
          this.ids = idArrFun()
          this.imgList = imgArrFun()
          const res = this.getRandom(num, this.ids)
          this.imgList.forEach((img) => {
            res.forEach(item => {
              if (img.id === item) {
                img.isShow = true
              }
            })
          })
        },
         // 获取随机数
        getRandom (num, ids) {
          // 输出数组
          const out = []
          // 输出个数
          while (out.length < num) {
            const temp = (Math.random() * ids.length) >> 0
            out.push(ids.splice(temp, 1)[0])
          }
          return out
        },
        // 倒计时
        countDown (seconds = 60) {
          // 定时器
          this.timeObj = dateTransform(seconds)
          this.timer = setInterval(() => {
            // 把转换后的结果显示出来
            this.timeObj = dateTransform(seconds)
            if (seconds < 0) {
              this.zeroHandle()
            }
            seconds--
          }, 1000)
        },
        // 生成泡泡逻辑
        zeroHandle () {
          clearInterval(this.timer)
          this.activeStarNum = this.activeStarNum + this.ruleData.wealthBonus
          this.countDown(this.ruleData.onlineTime)
          // 如果已经有了10个泡泡,就不往下执行了
          const imgHiddenList = this.imgList.filter(item => !item.isShow) || []
          if (imgHiddenList.length !== 0) {
            this.showBubble()
          }
        },
         // 显示泡泡
        showBubble () {
          // 如果泡泡数存在,下次就随机出现得范围就是isShow不为true得
          const resArr = this.imgList.filter(item => !item.isShow).map(i => i.id)
          if (resArr.length === 0) return
          this.ids = [...resArr]
          // 将出现的设置为true
          const res = this.getRandom(1, this.ids)
          this.imgList.forEach((img) => {
            res.forEach(item => {
              if (img.id === item) {
                img.isShow = true
              }
            })
          })
        },
      }
    

    注意: 从动画上来说,最重要的是在没有点击居中的时候,应该是按照UI图的样式进行10个球固定位置的分布,等点击收能量的时候,进行一个整体的动画,给一个过渡的效果,让每个球,做同样的操作,而不是针对单个球不同的位置做相应的操作

    从逻辑上来说,随机出现小球,一定要注意去排除已经出现过的小球.


    起源地下载网 » vue.js实现收能量

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    模板不会安装或需要功能定制以及二次开发?
    请QQ联系我们

    发表评论

    还没有评论,快来抢沙发吧!

    如需帝国cms功能定制以及二次开发请联系我们

    联系作者

    请选择支付方式

    ×
    迅虎支付宝
    迅虎微信
    支付宝当面付
    余额支付
    ×
    微信扫码支付 0 元