网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序電商常用倒計時

發布時間:2018-04-20 10:55 所屬欄目:小程序開發教程

wxml文件放個text

second: {{second}} micro second:{{micro_second}}

在js文件中調用

 

				
  1. function countdown(that) {
  2. var second = that.data.second
  3. if (second == 0) {
  4. // console.log("Time Out...");
  5. that.setData({
  6. second: "Time Out..."
  7. });
  8. return ;
  9. }
  10. var time = setTimeout(function(){
  11. that.setData({
  12. second: second - 1
  13. });
  14. countdown(that);
  15. }
  16. ,1000)
  17. }
  18.  
  19. Page({
  20. data: {
  21. second: 3
  22. },
  23. onLoad: function() {
  24. countdown(this);
  25. }
  26. });

運行驗證下,從10走到1s,然后顯示時間到。

于是繼續將毫秒完善,注意毫秒的步長受限于系統的時間頻率,于是我們精確到0.01s即10ms

js

 

				
  1. /* 秒級倒計時 */
  2. function countdown(that) {
  3. var second = that.data.second
  4. if (second == 0) {
  5. that.setData({
  6. second: "Time out!",
  7. micro_second: "micro_second too."
  8. });
  9. clearTimeout(micro_timer);
  10. return ;
  11. }
  12. var timer = setTimeout(function(){
  13. that.setData({
  14. second: second - 1
  15. });
  16. countdown(that);
  17. }
  18. ,1000)
  19. }
  20.  
  21. /* 毫秒級倒計時 */
  22. // 初始毫秒數,同時用作歸零
  23. var micro_second_init = 100;
  24. // 當前毫秒數
  25. var micro_second_current = micro_second_init;
  26. // 毫秒計時器
  27. var micro_timer;
  28.  
  29. function countdown4micro(that) {
  30. if (micro_second_current <= 0) {
  31. micro_second_current = micro_second_init;
  32. }
  33. micro_timer = setTimeout(function(){
  34. that.setData({
  35. micro_second: micro_second_current - 1
  36. });
  37. micro_second_current--;
  38. countdown4micro(that);


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23770.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×