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

mpvue小程序循環(huán)動(dòng)畫開啟暫停的實(shí)現(xiàn)方法

 更新時(shí)間:2019年05月15日 10:20:03   作者:tingzhong  
這篇文章主要介紹了mpvue小程序循環(huán)動(dòng)畫開啟暫停的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

用小程序的 animation 屬性實(shí)現(xiàn)循環(huán)動(dòng)畫的開啟與暫停,并封裝到組件。

實(shí)現(xiàn)一個(gè)字體圖標(biāo)組件的循環(huán)旋轉(zhuǎn)動(dòng)畫開啟/暫停

  1. 用于點(diǎn)擊圖標(biāo),字體顏色變換,開始循環(huán)旋轉(zhuǎn)動(dòng)畫,并刷新內(nèi)容
  2. 刷新結(jié)束,停止動(dòng)畫,并設(shè)置字體顏色為原來的
  3. 主要利用 setInterval 定時(shí)器循環(huán)執(zhí)行動(dòng)畫

首先,組件寫出來

添加點(diǎn)擊事件,動(dòng)畫屬性, style 屬性(用來動(dòng)態(tài)修改樣式)

src/components/refresh.vue

<template>
 <div>
  <div
   class="iconfont icon-shuaxin"
   :animation='refreshA'
   @click="refresh"
   :style='style'></div>
 </div>
</template>

設(shè)置初始數(shù)據(jù)

使用一個(gè) 布爾 數(shù)據(jù) refreshing 判斷動(dòng)畫的狀態(tài)為開啟 true /暫停 false

<script>
export default {
 data () {
  return {
   refreshA: null,
   style: 'color: #eee;',
   // 用來設(shè)置存儲旋轉(zhuǎn)的度數(shù)
   rotate: 0,
   // 存儲定時(shí)器id
   refreshI: null
  }
 },
 props: ['refreshing']
}
</script>

添加點(diǎn)擊事件函數(shù)

<script>
export default {
 methods: {
  // 刷新按鈕點(diǎn)擊
  refresh () {
   // 正在刷新 則跳出,避免在循環(huán)動(dòng)畫執(zhí)行時(shí),再次出發(fā)點(diǎn)擊刷新事件
   if (this.refreshing) return
   // 否則提交刷新事件
   this.$emit('refresh')
  },
  // 刷新動(dòng)畫結(jié)束
  refreshend () {
   // 當(dāng)動(dòng)畫結(jié)束,字體顏色恢復(fù)原來
   this.style = 'color: #eee;'
  }
 }
}
</script>

監(jiān)聽 refreshing 狀態(tài)

<script>
export default {
 watch: {
  refreshing (newV, oldV) {
   // 沒有正在刷新 > 正在刷新 設(shè)置循環(huán)動(dòng)畫
   if (newV && !oldV) {
    this.style = 'color: #fff;'
    this.refreshI = setInterval(() => {
    // 每次 +360 實(shí)現(xiàn)每 300 毫秒旋轉(zhuǎn) 360 度 
     this.rotate += 360
     let animation = wx.createAnimation()
     animation.rotateZ(this.rotate).step()
     this.refreshA = animation.export()
    }, 300)
    return
   }
   // 從正在刷新 > 刷新完成 清空循環(huán)定時(shí)器動(dòng)畫
   if (!newV && oldV) {
    clearInterval(this.refreshI)
    this.refreshA = null
   }
  }
 }
}
</script>

需要注意的是定時(shí)器時(shí)間必須和動(dòng)畫的過渡時(shí)間設(shè)置為相同

組件調(diào)用

src/pages/index/index.vue

<template>
 <div>
  <Refresh @refresh='refresh' :refreshing='refreshing'/>
 </div>
</template>

<script>
import Refresh from '@/components/refresh'

export default {
 data: {
  // 初始狀態(tài)肯定為 false ,點(diǎn)擊刷新組件后,在事件函數(shù)中再設(shè)置為 true
  refreshing: false
 },
 components: {
  Refresh
 },
 methods: {
  async refresh () {
  this.refreshing = true
  // 這里為一個(gè)異步請求api
  let data = await api.getData()
  // 請求完成,執(zhí)行想要操作的代碼后,設(shè)置動(dòng)畫為 false
  // this.data = data
  this.refreshing = false
  }
 }
}
</script>

<style lang="stylus" scoped>
</style>

refresh 組件完整代碼

<template>
 <div>
  <div
   class="iconfont icon-shuaxin"
   :animation='refreshA'
   @click="refresh"
   :style='style'></div>
 </div>
</template>

<script>
export default {
 data () {
  return {
   refreshA: null,
   style: 'color: #eee;',
   rotate: 0,
   refreshI: null
  }
 },
 props: ['refreshing'],
 watch: {
  refreshing (newV, oldV) {
   if (newV && !oldV) {
    this.style = 'color: #fff;'
    this.refreshI = setInterval(() => {
     this.rotate += 360
     let animation = wx.createAnimation()
     animation.rotateZ(this.rotate).step()
     this.refreshA = animation.export()
    }, 300)
    return
   }
   if (!newV && oldV) {
    clearInterval(this.refreshI)
    this.refreshA = null
   }
  }
 },
 methods: {
  refresh () {
   if (this.refreshing) return
   this.$emit('refresh')
  },
  refreshend () {
   this.style = 'color: #eee;'
  }
 }
}
</script>

<style lang="stylus" scoped>
</style>

效果

正常效果,看圖中右上角

網(wǎng)速太快

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

相關(guān)文章

  • Vue中設(shè)置背景圖片和透明度的簡單方法

    Vue中設(shè)置背景圖片和透明度的簡單方法

    在做項(xiàng)目的時(shí)候常需要設(shè)置背景圖片和透明度,下面這篇文章主要給大家介紹了關(guān)于Vue中設(shè)置背景圖片和透明度的簡單方法,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-01-01
  • vue中組件樣式?jīng)_突的問題解決

    vue中組件樣式?jīng)_突的問題解決

    默認(rèn)情況下,寫在.vue組件中的樣式會(huì)全局生效,因此很容易造成組件之間的樣式?jīng)_突問題,本文就來介紹一下如何解決此問題,感興趣的可以了解一下
    2023-12-12
  • 詳解Vue3-pinia狀態(tài)管理

    詳解Vue3-pinia狀態(tài)管理

    這篇文章主要介紹了Vue3-pinia狀態(tài)管理,pinia是?vue3?新的狀態(tài)管理工具,簡單來說相當(dāng)于之前?vuex,它去掉了?Mutations?但是也是支持?vue2?的,需要的朋友可以參考下
    2022-08-08
  • iView UI FORM 動(dòng)態(tài)添加表單項(xiàng)校驗(yàn)規(guī)則寫法實(shí)例

    iView UI FORM 動(dòng)態(tài)添加表單項(xiàng)校驗(yàn)規(guī)則寫法實(shí)例

    這篇文章主要為大家介紹了iView UI FORM 動(dòng)態(tài)添加表單項(xiàng)校驗(yàn)規(guī)則寫法實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • Vue.directive使用注意(小結(jié))

    Vue.directive使用注意(小結(jié))

    這篇文章主要介紹了Vue.directive使用注意(小結(jié)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08
  • vue點(diǎn)擊按鈕動(dòng)態(tài)創(chuàng)建與刪除組件功能

    vue點(diǎn)擊按鈕動(dòng)態(tài)創(chuàng)建與刪除組件功能

    這篇文章主要介紹了vue點(diǎn)擊按鈕動(dòng)態(tài)創(chuàng)建與刪除組件功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • Vue.js 中的 v-show 指令及用法詳解

    Vue.js 中的 v-show 指令及用法詳解

    v-show 指令通過改變元素的 css 屬性(display)來決定元素是顯示還是隱藏。這篇文章主要介紹了Vue.js 中的 v-show 指令及用法詳解,需要的朋友可以參考下
    2018-11-11
  • vue-resourc發(fā)起異步請求的方法

    vue-resourc發(fā)起異步請求的方法

    這篇文章主要介紹了vue-resourc發(fā)起異步請求的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Vue3多組件的N種編寫方式

    Vue3多組件的N種編寫方式

    Vue 本身以及周邊生態(tài)在設(shè)計(jì)語法糖上幾乎沒讓我失望過,包括本次亮相的 Vue Vine,它的出現(xiàn)引起了我對 Vue3 組件編寫方式的好奇,以及哪一種方式更接近「最佳實(shí)踐」?下面讓我來為大家一一道來
    2024-07-07
  • 在Vue框架中配置Mock服務(wù)器的方法

    在Vue框架中配置Mock服務(wù)器的方法

    在前端開發(fā)中,如果需要模擬后端數(shù)據(jù),而又不想開發(fā)一個(gè)后端服務(wù)器, 則可以借助mock.js配置一個(gè)后端服務(wù)器來返回前端需要的數(shù)據(jù),本文將會(huì)分別介紹在Quasar項(xiàng)目和Vite項(xiàng)目中Mock服務(wù)器的配置方法
    2022-12-12

最新評論