Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
用来判断,鼠标点击了哪个扇区 (Canvas)
$('#circle').on('touchstart',function(event){
//需要先判断点击了哪个扇区的位置
var x = event.originalEvent.touches[0].pageX - $('#circle')[0].getBoundingClientRect().left - 200;
var y = event.originalEvent.touches[0].pageY - $('#circle')[0].getBoundingClientRect().top - 200;
var anglePosition = Math.atan2(y,x);
var angle = 90 - anglePosition * (180/Math.PI);
if(angle < 0){
angle += 360;
}
var whichPath = 0;
for(var i=0;i<angles.length;i++){
if(angles[i] <= angle && angle < angles[i+1]){
whichPath = i;
break;
}else if(i === angles.length-1){
whichPath = i;
}
}
console.log(whichPath);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.