欢迎来到258分享网,纯净的网络源码分享基地!

258资源分享网

全部作品
全部作品
网站源码
微信源码
素材特效
源码插件
视频教程
建站学院
热门搜索: 织梦  农业种植  农业  安全设置  官方
258资源分享 > 建站学院 > 微信开发 > 微信小程序的this和that,触摸水波涟漪效果

推荐下载

HTML5响应式自适应网咯设计

2020-05-12   浏览:740

高端HTML5响应式企业通用网

2020-05-06   浏览:521

html5响应式外贸网站英文版

2020-05-08   浏览:510

HTML5自适应律师工作室类网

2020-04-04   浏览:504

HTML5影视传媒文化公司类网

2020-05-12   浏览:502

微信小程序的this和that,触摸水波涟漪效果

发布时间:2020-12-06  
一:this和that

分享者:别寒,原文地址 
微信小程序中,在wx.request({});方法调用成功或者失败之后,有时候会需要获取页面初始化数据data的情况,这个时候,如果使用,this.data来获取,会出现获取不到的情况,调试页面也会报undefiend。原因是,在javascript中,this代表着当前对象,会随着程序的执行过程中的上下文改变,在wx.request({});方法的回调函数中,对象已经发生改变,所以已经不是wx.request({});方法对象了,data属性也不存在了。官方的解决办法是,复制一份当前的对象,如下:

var that=this;//把this对象复制到临时变量that 
在success回调函数中使用that.data就能获取到数据了。

不过,还有另外一种方式,也很特别,是将success回调函数换一种声明方式,如下:

 

success: res =>{

this.setData({

loadingHidden: true,

hideCommitSuccessToast: false

})

}

在这种方式下,this可以直接使用,完全可以获取到data数据。

再给一个完整的例子:

 

success: res => {

if (res.data.code != 0) {

// 提交失败

this.setData({

loadingHidden: true,

hiddenTips: false,

tipsContent: res.data.message

})

} else {

// 提交成功

this.setData({

loadingHidden: true,

hideCommitSuccessToast: false

})

subBtn = false;

 

// 定时,3秒消失

setTimeout(() => {

this.setData({

hideCommitSuccessToast: true

})

wx.navigateBack({ delta: 2 });

}, 2000);

 

}

}

 

二:触摸水波涟漪效果

分享者:未知,原文地址  效果

html代码

 

<view class="ripple" style="{{rippleStyle}}"></view>

<view class="container" bindtouchstart="containerTap"></view>

css代码

 

.container{

width:100%;

height:500px;

}

.ripple {

background-color: rgba(0, 0, 0, 0.8);

border-radius: 100%;

height:10px;

width:10px;

margin-top: -90px;

position: absolute;

-webkit-transform: scale(0);

}

@-webkit-keyframes ripple {

100% {

-webkit-transform: scale(12);

transform: scale(12);

background-color: transparent;

}

}

js代码

 

containerTap:function(res){

console.log(res.touches[0]);

var x=res.touches[0].pageX;

var y=res.touches[0].pageY+85;

this.setData({

rippleStyle:''

});

this.setData({

rippleStyle:'top:'+y+'px;left:'+x+'px;-webkit-animation: ripple 0.4s linear;animation:ripple 0.4s linear;'