国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 課堂 > 小程序 > 正文

微信小程序開發(fā)之自定義toast實例講解

2020-03-21 16:25:17
字體:
供稿:網(wǎng)友

本來是比較好的,方便使用,但是這個toast會顯示出圖標(biāo),而且不能去除。

假設(shè):我們執(zhí)行完業(yè)務(wù)的時候,toast一下,當(dāng)執(zhí)行成功的時候,效果還可以接受,如下圖:

微信小程序,小程序開發(fā),toast

但是,當(dāng)執(zhí)行失敗的時候,如下圖:

失敗了,你還顯示個扣扣圖案,那到底是成功還是失敗??這肯定是不能接受的。【捂臉】

若是給老板看到這種效果,又是一頓臭罵,程序猿的委屈哭

微信小程序,小程序開發(fā),toast

下面介紹一個自定義的toast

效果:

微信小程序,小程序開發(fā),toast

具體實現(xiàn):

wxml:

  1. button 
  2.  
  3. {{toastText}} 

wxss:

  1. Page { 
  2.  
  3. background#fff
  4.  
  5.  
  6. /*按鈕*/ 
  7.  
  8. .btn { 
  9.  
  10. font-size28rpx; 
  11.  
  12. padding15rpx 30rpx; 
  13.  
  14. width100rpx; 
  15.  
  16. margin20rpx; 
  17.  
  18. text-aligncenter
  19.  
  20. border-radius: 10rpx; 
  21.  
  22. border1px solid #000
  23.  
  24.  
  25. /*mask*/ 
  26.  
  27. .toast_mask { 
  28.  
  29. opacity: 0
  30.  
  31. width100%
  32.  
  33. height100%
  34.  
  35. overflowhidden
  36.  
  37. positionfixed
  38.  
  39. top: 0
  40.  
  41. left: 0
  42.  
  43. z-index888
  44.  
  45.  
  46. /*toast*/ 
  47.  
  48. .toast_content_box { 
  49.  
  50. display: flex; 
  51.  
  52. width100%
  53.  
  54. height100%
  55.  
  56. justify-contentcenter
  57.  
  58. align-items: center
  59.  
  60. positionfixed
  61.  
  62. z-index999
  63.  
  64.  
  65. .toast_content { 
  66.  
  67. width50%
  68.  
  69. padding20rpx; 
  70.  
  71. background: rgba(0000.5); 
  72.  
  73. border-radius: 20rpx; 
  74.  
  75.  
  76. .toast_content_text { 
  77.  
  78. height100%
  79.  
  80. width100%
  81.  
  82. color#fff
  83.  
  84. font-size28rpx; 
  85.  
  86. text-aligncenter
  87.  

js:

  1. Page({ 
  2.  
  3. data: { 
  4.  
  5. //toast默認(rèn)不顯示 
  6.  
  7. isShowToast: false 
  8.  
  9. }, 
  10.  
  11. showToast: function () { 
  12.  
  13. var _this = this
  14.  
  15. // toast時間 
  16.  
  17. _this.data.count = parseInt(_this.data.count) ? parseInt(_this.data.count) : 3000; 
  18.  
  19. // 顯示toast 
  20.  
  21. _this.setData({ 
  22.  
  23. isShowToast: true
  24.  
  25. }); 
  26.  
  27. // 定時器關(guān)閉 
  28.  
  29. setTimeout(function () { 
  30.  
  31. _this.setData({ 
  32.  
  33. isShowToast: false 
  34.  
  35. }); 
  36.  
  37. }, _this.data.count); 
  38.  
  39. }, 
  40.  
  41. /* 點擊按鈕 */ 
  42.  
  43. clickBtn: function () { 
  44.  
  45. console.log("你點擊了按鈕"
  46.  
  47. //設(shè)置toast時間,toast內(nèi)容 
  48.  
  49. this.setData({ 
  50.  
  51. count: 1500, 
  52.  
  53. toastText: 'Michael’s Toast' 
  54.  
  55. }); 
  56.  
  57. this.showToast(); 
  58.  
  59.  
  60. }) 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 黄梅县| 嘉义市| 高州市| 射洪县| 沈阳市| 特克斯县| 江川县| 万年县| 蒙城县| 商城县| 宁德市| 泽州县| 贡嘎县| 新蔡县| 宜阳县| 睢宁县| 天全县| 延吉市| 景东| 开封县| 新闻| 依安县| 盐边县| 鄂伦春自治旗| 大理市| 抚松县| 高青县| 高要市| 通山县| 青州市| 奉新县| 于都县| 绥芬河市| 阿瓦提县| 涿鹿县| 甘孜县| 法库县| 鹤山市| 霍林郭勒市| 永兴县| 民和|