最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

vue實(shí)現(xiàn)宮格輪轉(zhuǎn)抽獎(jiǎng)(類似穿越火線的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: "未中獎(jiǎng)", 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元話費(fèi)", val: 12, img: "", index: 11, active: false },
      ],
      isAnimate: false, // 為 true時(shí)代表正在抽獎(jiǎng),當(dāng)前抽獎(jiǎng)未結(jié)束時(shí)點(diǎn)擊抽獎(jiǎng)按鈕無效
      jumpIndex:  Math.floor(Math.random() * 12), // 抽獎(jiǎng)輪跳時(shí)的索引
      jumpingTime: 0, // 正在輪跳的時(shí)間
      jumpingTotalTime: 0,  // 輪跳的時(shí)間總量,基于 duration 變量加上一個(gè) 0~1000 之間的隨機(jī)數(shù)組成
      jumpingChange: 0, // 輪跳速率峰值,基于 velocity 變量加上一個(gè) 0~3 之間的隨機(jī)數(shù)組成
      duration: 4500,  // 持續(xù)時(shí)間
      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 方法所消耗的時(shí)間

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

      // 輪訓(xùn)動(dòng)畫
      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));
    },

    /**
     * 緩動(dòng)函數(shù),由快到慢
     * @param {Num} t 當(dāng)前時(shí)間
     * @param {Num} b 初始值
     * @param {Num} c 變化值
     * @param {Num} d 持續(xù)時(shí)間
     */
    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: "點(diǎn)擊抽獎(jiǎng)";
          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)整中獎(jiǎng)的概率,如果有比較好的想法的小伙伴們也非常歡迎一起來探討一下

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

相關(guān)文章

  • 關(guān)于Element?table組件滾動(dòng)條不顯示的踩坑記錄

    關(guān)于Element?table組件滾動(dòng)條不顯示的踩坑記錄

    這篇文章主要介紹了關(guān)于Element?table組件滾動(dòng)條不顯示的踩坑記錄,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue生命周期beforeDestroy和destroyed調(diào)用方式

    vue生命周期beforeDestroy和destroyed調(diào)用方式

    這篇文章主要介紹了vue生命周期beforeDestroy和destroyed調(diào)用方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • Vue項(xiàng)目中是否使用store原理深究

    Vue項(xiàng)目中是否使用store原理深究

    這篇文章主要為大家介紹了在Vue項(xiàng)目中是否使用store原理深究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • vue-cli 引入jQuery,Bootstrap,popper的方法

    vue-cli 引入jQuery,Bootstrap,popper的方法

    這篇文章主要介紹了vue-cli 引入jQuery,Bootstrap,popper的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-09-09
  • vue3 Class 與 Style 綁定操作方法

    vue3 Class 與 Style 綁定操作方法

    數(shù)據(jù)綁定的一個(gè)常見需求場景是操縱元素的 CSS class 列表和內(nèi)聯(lián)樣式,因?yàn)?nbsp;class 和 style 都是 attribute,我們可以和其他 attribute 一樣使用 v-bind 將它們和動(dòng)態(tài)的字符串綁定,這篇文章主要介紹了vue3 Class 與 Style 綁定操作方法,需要的朋友可以參考下
    2024-05-05
  • vue 解決addRoutes動(dòng)態(tài)添加路由后刷新失效問題

    vue 解決addRoutes動(dòng)態(tài)添加路由后刷新失效問題

    這篇文章主要介紹了vue 解決addRoutes動(dòng)態(tài)添加路由后刷新失效問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-07-07
  • vue簡單的二維數(shù)組循環(huán)嵌套方式

    vue簡單的二維數(shù)組循環(huán)嵌套方式

    這篇文章主要介紹了vue簡單的二維數(shù)組循環(huán)嵌套方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue使用高德地圖實(shí)現(xiàn)軌跡顯隱效果

    vue使用高德地圖實(shí)現(xiàn)軌跡顯隱效果

    本文主要介紹了在vue中如何使用高德地圖實(shí)現(xiàn)軌跡顯隱的功能,包括了相關(guān)代碼的編寫和具體實(shí)現(xiàn)步驟,對于想要在自己的項(xiàng)目中使用這一功能的開發(fā)者有一定的參考價(jià)值,希望大家對此有所幫助,同時(shí)也歡迎大家多多支持腳本之家
    2024-10-10
  • vue中集成省市區(qū)街四級地址組件的實(shí)現(xiàn)過程

    vue中集成省市區(qū)街四級地址組件的實(shí)現(xiàn)過程

    我們在開發(fā)中常會(huì)遇到選擇地址的需求,有時(shí)候只需要選擇省就可以,有時(shí)候則需要選擇到市、縣,以至于鄉(xiāng)鎮(zhèn),甚至哪個(gè)村都有可能,下面這篇文章主要給大家介紹了關(guān)于vue中集成省市區(qū)街四級地址組件的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • 搭建vue3項(xiàng)目以及按需引入element-ui框架組件全過程

    搭建vue3項(xiàng)目以及按需引入element-ui框架組件全過程

    element是基于vue.js框架開發(fā)的快速搭建前端的UI框架,下面這篇文章主要給大家介紹了關(guān)于搭建vue3項(xiàng)目以及按需引入element-ui框架組件的相關(guān)資料,文中通過圖文以及代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-02-02

最新評論

新田县| 措美县| 雷波县| 太谷县| 云阳县| 惠水县| 门头沟区| 莱州市| 阳高县| 连江县| 台前县| 钟祥市| 自贡市| 沙洋县| 溧水县| 鄂伦春自治旗| 宣武区| 嘉黎县| 福泉市| 潍坊市| 额济纳旗| 沛县| 徐水县| 左贡县| 安远县| 台前县| 乌鲁木齐县| 河曲县| 绵竹市| 鄂托克旗| 宝鸡市| 宁乡县| 东阳市| 叶城县| 安阳县| 平乡县| 句容市| 宁明县| 泰兴市| 枝江市| 佛教|