拖拽转动

me.prototype.spinPieStart = function(e){

var event = e.originalEvent;

var touch = event.targetTouches ? event.targetTouches[0] : e;

 

e.stopPropagation();

 

// recalibrate pieCenter in case page has been scrolled

var pageTop = this.pieDish.offset().top;

var pageLeft = this.pieDish.offset().left;

this.pieCenter = {x: this.startPieCenter.x - (this.pageLeft - pageLeft) , y:this.startPieCenter.y - (this.pageTop - pageTop)};

 

// differentiate between move and click

this.moved = false;

this.startPos = {x:touch.pageX, y:touch.pageY};

 

// figure out where the user touched relative to the pie center

var location = {x:touch.pageX - this.pieCenter.x, y:touch.pageY - this.pieCenter.y}

 

this.startAngle = Math.atan2(location.y,location.x);

this.manualSpin = true;

}

 

me.prototype.spinPieMove = function(e){

e.stopPropagation();

e.preventDefault();

 

if (this.manualSpin){

 

var event = e.originalEvent;

var touch = event.targetTouches ? event.targetTouches[0] : e;

 

var location = {x:touch.pageX - this.pieCenter.x, y:touch.pageY - this.pieCenter.y};

this.currentAngle = Math.atan2(location.y,location.x);

this.newAngle = this.finalAngle + (this.currentAngle - this.startAngle);

this.newAngle = this.newAngle % (Math.PI * 2);

this.$canvas.moveRelative({rotateDeg: this.radian2Deg(this.newAngle), speed:0, removeTiming:false});

if (Math.abs(this.startPos.x - location.x) > 5 || Math.abs(this.startPos.x - location.y > 5)) {

this.moved = true;

}

}

}

 

me.prototype.spinPieStop = function(e){

var ev;

 

e.stopPropagation();

e.preventDefault();

 

if (this.manualSpin){

 

// detect click

if (!this.moved){

ev = document.createEvent('MouseEvents');

ev.initMouseEvent('click', true, true, e.view, 1,

this.startPos.x, this.startPos.y, this.startPos.x, this.startPos.y,

e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,

0, null);

ev._fake = true;

this.$canvas[0].dispatchEvent(ev);

} else {

// spin stop

this.finalAngle = this.newAngle;

this.setCurrentSegment();

}

}

this.manualSpin = false;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值