var app = getApp()
Page({
data: {
imgwidth:0,
imgheight:0,
animationData: {},
movex:0,
movey:0,
x:0,
y:0,
},
onLoad: function() {
var _this = this;
wx.getSystemInfo({
success: function(res) {
_this.setData({
screenHeight: res.windowHeight,
screenWidth: res.windowWidth,
});
}
});
},
onReady:function(){
this.animation = wx.createAnimation({
duration: 1000,
timingFunction: 'linear',
transformOrigin: "left top 0px",
})
},
imageLoad: function(e) {
var _this=this;
var cnt_offetw=_this.data.screenWidth-38,
cnt_offeth=(_this.data.screenHeight-38)*0.7;
var $width=e.detail.width,
$height=e.detail.height,
ratio=$width/$height;
var viewWidth=_this.data.screenWidth;
var viewHeight=parseInt(viewWidth/ratio);
if (viewHeight< cnt_offeth) {
viewHeight=cnt_offeth;
}
_this.setData({
imgwidth:viewWidth,
imgheight:viewHeight,
cnt_boxw:cnt_offetw,
cnt_boxh:cnt_offeth,
})
},
startEvent:function(e){
this.setData({
startx: e.touches[0].pageX,
starty: e.touches[0].pageY
})
},
moveEvent: function(e) {
var _this=this;
var pageX = e.touches[0].pageX;
var pageY = e.touches[0].pageY;
var x,y;
var endx=_this.data.x,endy=_this.data.y;
var w_x=_this.data.imgwidth-_this.data.cnt_boxw;
var h_y=parseInt(_this.data.imgheight-_this.data.cnt_boxh);
var DistanceX = pageX - _this.data.startx;
var DistanceY =pageY - _this.data.starty;
if (DistanceX>0){
if (endx >= 0) {
x = 0;
} else {
x = endx + DistanceX;
}
}else{
if (w_x >= endx) {
x = -w_x;
} else {
x = endx + DistanceX;
}
}
if (DistanceY>0){
if(endy>=0){
y =0;
}else{
y = endy + DistanceY;
}
}else{
if(-endy==h_y||-endy>h_y){
y=-h_y;
console.log("da0")
}else{
y=endy+DistanceY;
console.log("da 1")
}
}
setTimeout(function() {
_this.animation.translate(x, y).step();
_this.setData({
animationData: this.animation.export()
})
}.bind(this), 0)
_this.setData({
x:x,
y:y,
})
endx=x;endy=y;
_this.data.startx=pageX;_this.data.starty=pageY;
},
endEvent:function(){
clearTimeout(function(){
this.animation.translate(this.data.x,this.data.y).step();
this.setData({
animationData: this.animation.export()
})
});
}
})