欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue實現(xiàn)宮格輪轉(zhuǎn)抽獎

 更新時間:2021年11月14日 08:41:59   作者:Cy.Lau  
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)宮格輪轉(zhuǎn)抽獎,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

vue實現(xiàn)宮格輪轉(zhuǎn)抽獎(類似穿越火線的xx輪回),供大家參考,具體內(nèi)容如下

不做過多的解說,直接上代碼啦。關(guān)鍵的代碼都寫了注釋,很容易理解。直接復(fù)制即可使用!
另外css部分依賴 node-sass、sass-loader,沒有安裝的安裝一下,已有的小伙伴直接跳過~~

"node-sass": "^4.12.0",
"sass-loader": "^8.0.2",

<template>
  <div class="home">
    <div class="home-container">
      <div class="home-container-line">
        <div
          class="home-container-line-box"
          v-for="item in list.slice(0, 5)"
          :key="item.index"
          :class="{ selected: item.active }"
        >
          {{ item.label }}
        </div>
      </div>
      <div class="home-container-line">
        <div
          class="home-container-line-box"
          v-for="item in list.slice(11, 12)"
          :key="item.index"
          :class="{ selected: item.active }"
        >
          {{ item.label }}
        </div>
        <div class="home-container-line-btn" @click="handleClick" :disable="isAnimate"></div>
        <div
          class="home-container-line-box"
          v-for="item in list.slice(5, 6)"
          :key="item.index"
          :class="{ selected: item.active }"
        >
          {{ item.label }}
        </div>
      </div>
      <div class="home-container-line">
        <div
          class="home-container-line-box"
          v-for="item in Array.prototype.reverse.call(list.slice(6, 11))"
          :key="item.index"
          :class="{ selected: item.active }"
        >
          {{ item.label }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Luck",
  data() {
    return {
      list: [
        { label: "未中獎", val: 1, img: "", index: 0, active: false },
        { label: "大保健", val: 2, img: "", index: 1, active: false },
        { label: "iPhone13", val: 3, img: "", index: 2, active: false },
        { label: "MacBook Pro", val: 4, img: "", index: 3, active: false },
        { label: "MacBook Air", val: 5, img: "", index: 4, active: false },
        { label: "1積分", val: 6, img: "", index: 5, active: false },
        { label: "5積分", val: 7, img: "", index: 6, active: false },
        { label: "10積分", val: 8, img: "", index: 7, active: false },
        { label: "小愛同學(xué)", val: 9, img: "", index: 8, active: false },
        { label: "安慕希酸奶", val: 10, img: "", index: 9, active: false },
        { label: "清空購物車", val: 11, img: "", index: 10, active: false },
        { label: "50元話費", val: 12, img: "", index: 11, active: false },
      ],
      isAnimate: false, // 為 true時代表正在抽獎,當(dāng)前抽獎未結(jié)束時點擊抽獎按鈕無效
      jumpIndex:  Math.floor(Math.random() * 12), // 抽獎輪跳時的索引
      jumpingTime: 0, // 正在輪跳的時間
      jumpingTotalTime: 0,  // 輪跳的時間總量,基于 duration 變量加上一個 0~1000 之間的隨機(jī)數(shù)組成
      jumpingChange: 0, // 輪跳速率峰值,基于 velocity 變量加上一個 0~3 之間的隨機(jī)數(shù)組成
      duration: 4500,  // 持續(xù)時間
      velocity: 300,  // 速率
    };
  },
  methods: {
    handleClick() {
      if(this.isAnimate) return;
      this.jumpingTime = 0;
      this.jumpingTotalTime = Math.random() * 1000 + this.duration;
      this.jumpingChange = Math.random() * 3 + this.velocity;
      this.animateRound(this.jumpIndex);
    },

    animateRound(index) {
      this.isAnimate = true; 
      if(this.jumpIndex < this.list.length - 1 )  this.jumpIndex ++;
      if(this.jumpIndex >= this.list.length - 1 )  this.jumpIndex = 0;

      this.jumpingTime += 100;  // 每一幀執(zhí)行 setTimeout 方法所消耗的時間

      // 如果當(dāng)前時間大于時間總量后, 退出動畫,  清算獎品
      if(this.jumpingTime >= this.jumpingTotalTime){
        this.isAnimate = false; 
        if(index == 0) {
          alert(`很遺憾沒有抽到獎品,再接再厲哦~`);
        }
        else{
          alert(`恭喜您抽到了:${this.list[index].label}`)
        }
        return
      }

      // 輪訓(xùn)動畫
      if (index >= this.list.length-1) {
        index = 0;
        this.list[11].active = false;
        this.list[index].active = true;
        index -= 1;
      } else {
        this.list[index].active = false;
        this.list[index + 1].active = true;
      }

      setTimeout(() => {
        this.animateRound(index + 1);
      }, this.easeOut(this.jumpingTime, 0, this.jumpingChange, this.jumpingTotalTime));
    },

    /**
     * 緩動函數(shù),由快到慢
     * @param {Num} t 當(dāng)前時間
     * @param {Num} b 初始值
     * @param {Num} c 變化值
     * @param {Num} d 持續(xù)時間
     */
    easeOut(t, b, c, d) {
      if ((t /= d / 2) < 1) return (c / 2) * t * t + b;
      return (-c / 2) * (--t * (t - 2) - 1) + b;
    },
  },
};
</script>
<style lang="scss" scoped>
.center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.home {
  padding: 0;
  margin: 0;
  width: 100%;
  height: calc(100vh - 16px);
  background-image: linear-gradient(25deg, #30007c, #464995, #4d83ad, #41bfc4);
  @extend .center;
  &-container {
    width: 1000px;
    height: 600px;
    &-line {
      width: 100%;
      height: 198px;
      display: flex;
      &-box {
        flex: 1;
        overflow: hidden;
        margin: 5px 3px 5px 3px;
        @extend .center;
        background: #fff;
        transition: all .3s;
      }
      &-btn {
        position: relative;
        flex: 3;
        overflow: hidden;
        margin: 5px 3px 3px 3px;
        @extend .center;
        box-shadow: 0 1px 10px 0px #cf5531;
        background-image: linear-gradient(
          25deg,
          #cf5531,
          #d0853a,
          #cdaf43,
          #c4d84d
        );
        cursor: pointer;
        &:active {
          background-image: linear-gradient(
            25deg,
            #3f3e41,
            #6d6340,
            #9a8b39,
            #c9b629
          );
        }
        &::before {
          position: absolute;
          content: "點擊抽獎";
          font-size: 2.5rem;
          color: #fff;
          font-weight: bold;
        }
      }
    }
  }
}
.selected {
  background: rgba($color: #f6e58d, $alpha: 0.5);
  animation-name: twinkle;
  animation-duration: 3s;
  animation-iteration-count: infinite;
}
@keyframes twinkle {
  0%   {background:#ffbe76;}
 100% {background:#f6e58d;}
}
</style>

效果圖:

最后特別說明一下,概率完全是隨機(jī)的。目前還沒有特別好的思路去調(diào)整中獎的概率,如果有比較好的想法的小伙伴們也非常歡迎一起來探討一下

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue引入組件的幾種方法匯總

    vue引入組件的幾種方法匯總

    這篇文章主要介紹了vue引入組件的幾種方法匯總,包括常用的局部引入,這里需要注意在哪個頁面需要就在那個頁面引入、注冊、使用,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2023-10-10
  • 在Vue中使用echarts的實例代碼(3種圖)

    在Vue中使用echarts的實例代碼(3種圖)

    本篇文章主要介紹了在Vue中使用echarts的實例代碼(3種圖),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • vue-cli+webpack記事本項目創(chuàng)建

    vue-cli+webpack記事本項目創(chuàng)建

    這篇文章主要為大家詳細(xì)介紹了vue-cli+webpack創(chuàng)建記事本項目,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • vue-print-nb實現(xiàn)頁面打印功能實例(含分頁打印)

    vue-print-nb實現(xiàn)頁面打印功能實例(含分頁打印)

    在項目中,有時需要打印頁面的表格,在網(wǎng)上找了一個打印組件vue-print-nb,用了還不錯,所以下面這篇文章主要給大家介紹了關(guān)于vue-print-nb實現(xiàn)頁面打印功能的相關(guān)資料,需要的朋友可以參考下
    2022-08-08
  • element-ui表格如何自適應(yīng)高度效果示例

    element-ui表格如何自適應(yīng)高度效果示例

    這篇文章主要給大家介紹了關(guān)于element-ui表格如何自適應(yīng)高度的相關(guān)資料,Element UI的Table組件默認(rèn)情況下是沒有自適應(yīng)高度的,文中給大家介紹了解決的辦法,需要的朋友可以參考下
    2023-08-08
  • 使用github部署前端vue項目

    使用github部署前端vue項目

    這篇文章主要為大家介紹了使用github部署前端vue項目過程示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • vue eslint簡要配置教程詳解

    vue eslint簡要配置教程詳解

    這篇文章主要介紹了vue eslint簡要配置,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • Vue路由前后端設(shè)計總結(jié)

    Vue路由前后端設(shè)計總結(jié)

    在本篇文章里小編給大家整理的是關(guān)于Vue路由前后端設(shè)計的知識點總結(jié)內(nèi)容,需要的朋友們參考下。
    2019-08-08
  • 淺談vue-router 路由傳參的方法

    淺談vue-router 路由傳參的方法

    這篇文章主要介紹了淺談vue-router 路由傳參的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • Vue+mui實現(xiàn)圖片的本地緩存示例代碼

    Vue+mui實現(xiàn)圖片的本地緩存示例代碼

    這篇文章主要介紹了Vue+mui實現(xiàn)圖片的本地緩存的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-05-05

最新評論