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

微信小程序?qū)崙?zhàn)之自定義toast(6)

 更新時(shí)間:2017年04月18日 10:10:17   作者:michael_ouyang  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崙?zhàn)之自定義toast的相關(guān)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

微信提供了一個(gè)toast的api  wx.showToast()
相關(guān)連接:https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-react.html#wxshowtoastobject 

本來(lái)是比較好的,方便使用,但是這個(gè)toast會(huì)顯示出圖標(biāo),而且不能去除。
假設(shè):我們執(zhí)行完業(yè)務(wù)的時(shí)候,toast一下,當(dāng)執(zhí)行成功的時(shí)候,效果還可以接受,如下圖:

 

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

失敗了,你還顯示個(gè)圖案,那到底是成功還是失????這肯定是不能接受的。

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

下面介紹一個(gè)自定義的toast

效果:

具體實(shí)現(xiàn):
wxml:

<!--按鈕--> 
<view style="{{isShowToast?'position:fixed;':''}}"> 
 <view class="btn" bindtap="clickBtn">button</view> 
</view> 
 
<!--mask--> 
<view class="toast_mask" wx:if="{{isShowToast}}"></view> 
<!--以下為toast顯示的內(nèi)容--> 
<view class="toast_content_box" wx:if="{{isShowToast}}"> 
 <view class="toast_content"> 
 <view class="toast_content_text"> 
  {{toastText}} 
 </view> 
 </view> 
</view> 

wxss:

Page { 
 background: #fff; 
} 
/*按鈕*/ 
.btn { 
 font-size: 28rpx; 
 padding: 15rpx 30rpx; 
 width: 100rpx; 
 margin: 20rpx; 
 text-align: center; 
 border-radius: 10rpx; 
 border: 1px solid #000; 
} 
/*mask*/ 
.toast_mask { 
 opacity: 0; 
 width: 100%; 
 height: 100%; 
 overflow: hidden; 
 position: fixed; 
 top: 0; 
 left: 0; 
 z-index: 888; 
} 
/*toast*/ 
.toast_content_box { 
 display: flex; 
 width: 100%; 
 height: 100%; 
 justify-content: center; 
 align-items: center; 
 position: fixed; 
 z-index: 999; 
} 
.toast_content { 
 width: 50%; 
 padding: 20rpx; 
 background: rgba(0, 0, 0, 0.5); 
 border-radius: 20rpx; 
} 
.toast_content_text { 
 height: 100%; 
 width: 100%; 
 color: #fff; 
 font-size: 28rpx; 
 text-align: center; 
} 

js:

Page({ 
 data: { 
 //toast默認(rèn)不顯示 
 isShowToast: false 
 }, 
 showToast: function () { 
 var _this = this; 
 // toast時(shí)間 
 _this.data.count = parseInt(_this.data.count) ? parseInt(_this.data.count) : 3000; 
 // 顯示toast 
 _this.setData({ 
  isShowToast: true, 
 }); 
 // 定時(shí)器關(guān)閉 
 setTimeout(function () { 
  _this.setData({ 
  isShowToast: false 
  }); 
 }, _this.data.count); 
 }, 
 /* 點(diǎn)擊按鈕 */ 
 clickBtn: function () { 
 console.log("你點(diǎn)擊了按鈕") 
 //設(shè)置toast時(shí)間,toast內(nèi)容 
 this.setData({ 
  count: 1500, 
  toastText: 'Michael's Toast' 
 }); 
 this.showToast(); 
 } 
}) 

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

相關(guān)文章

最新評(píng)論