溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

小程序條形倒計時動畫怎么實現(xiàn)

發(fā)布時間:2022-03-07 09:19:55 來源:億速云 閱讀:209 作者:iii 欄目:開發(fā)技術(shù)

今天小編給大家分享一下小程序條形倒計時動畫怎么實現(xiàn)的相關(guān)知識點,內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

一、效果圖如下:

小程序條形倒計時動畫怎么實現(xiàn)

二、wxml

<view class='headpiece-time flex-row'><text class='headpiece-txt'>倒計時:</text><view class='headpiece-process'><view class='headpiece-process-inner' style="width:{{width}}%"></view></view><text class='headpiece-num'>{{t}}</text></view>

三、wxss

headpiece-num {position: absolute;top: -3rpx;right: -35rpx;width: 62rpx;height: 100%;text-align: center;} .headpiece-time {position: relative;width: 305rpx;} .headpiece-process {position: relative;width: 138rpx;height: 14rpx;margin-right: 14rpx;border: 4rpx solid #000;overflow: hidden;background: #fff4b2;} .headpiece-process-inner {position: absolute;top: 0rpx;left: 0rpx;background: #f74242;height: 100%;transition: all 0.3s ease-out;}.

四、index.js

  1. /**

  2. * 獲取系統(tǒng)信息

  3. */

  4. getSystemInfo: function () {

  5. return new Promise((a, b) => {

  6. wx.getSystemInfo({

  7. success: function (res) {

  8. a(res)

  9. },

  10. fail: function (res) {

  11. b(res)

  12. }

  13. })

  14. })

  15. },

  16. /**

  17. * 進度條動畫

  18. */

  19. countdown: function () {

  20. const requestAnimationFrame = callback => {

  21. return setTimeout(callback, 1000 / 60);

  22. }, cancelAnimationFrame = id => {

  23. clearTimeout(id);

  24. };

  25.  

  26. this.getSystemInfo().then(v => {

  27. let maxtime = this.data.maxtime,

  28. width = this.data.width,

  29. sTime = +new Date,

  30. _ts = this,

  31. temp,

  32. animate;

  33. (animate = () => {

  34. temp = requestAnimationFrame(() => {

  35. let time = maxtime * 1000,

  36. currentTime = +new Date,

  37. schedule = 1 - (currentTime - sTime) / time,

  38. schedule_1 = schedule <= 0 ? 0 : schedule,

  39. width = parseInt(schedule_1 * 100),

  40. t = parseInt((this.data.maxtime) * schedule_1)+1;

  41. _ts.setData({

  42. width: width,

  43. t:t

  44. });

  45. if (schedule <= 0) {

  46. cancelAnimationFrame(temp);

  47. _ts.setData({

  48. width: width,

  49. t: 0

  50. });

  51. return;

  52. } else {

  53. animate();

  54. };

  55. })

  56. })();

  57.  

  58. });

  59. },


以上就是“小程序條形倒計時動畫怎么實現(xiàn)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI