360旋转

使用throttle方法
此方法没有this
既然知道在onLoad对象下this是对的,那就用一个全局变量在onLoad中初始化保存一下这个this,然后在pullUp方法中使用这个全局变量进行调用。

在script开头, export default{} 代码块之前,初始化一个变量

//

let _this= null;

//export default {undefined

在onLoad中进行初始化

onload(){undefined

_this=this;

this.loadData();

}

export const throttle = (func, wait) => {
	var context, args, timeout, result;
	var previous = 0;
	var later = function () {
		previous = new Date();
		timeout = null;
		result = func.apply(context, args);
	};
	return function () {
		var now = new Date();
		var remaining = wait - (now - previous);
		context = this;
		args = arguments;
		if (remaining <= 0) {
				clearTimeout(timeout);
				timeout = null;
				previous = now;
				result = func.apply(context, args);
		} else if (!timeout) {
				timeout = setTimeout(later, remaining);
		}
		return result;
	};
};

360主体旋转

imageTouchmove:throttle((e) => {
	let that = _this;
	if (that.viewing) {
		let self = {
			x: that.touchstart.pageX,
			y: that.touchstart.pageY
		}
		let touch = e.touches[0] || e.changedTouches[0];
		let x = touch.pageX, y = touch.pageY;
		let angle = 180 * Math.atan((y - self.y) / (x - self.x)) / Math.PI;
		if (Math.abs(angle) < 20) {
			let index = that.imageIndex + (x > self.x ? 1 : -1);
			that.$set(that.touchstart, 'pageX', x);
			that.$set(that.touchstart, 'pageY', y);
			console.log(index, that.imagesList.length)
			if (index >= that.imagesList.length) {
					index = 0;
			}
			if (index < 0) {
					index = that.imagesList.length-1;
			}
			if (index != that.imageIndex) {
					that.imageIndex = index;
			}
			e.preventDefault();
		}
	}
	},50),
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值