我编写了这个脚本来在网页中制作一个可转动的按钮。它工作得很好,但它不想退出该功能。它继续运行括号内的代码。知道我该如何解决吗?这是我现在拥有的代码。
如果您按下鼠标并拖动,则该值将发生变化。但现在它无处不在,只有当你点击按钮而不是拖动时才会发生这种情况。
function pressed(){
var PosibleVal = new Array(8,41,74,107,140,174);
$(window).on("mousemove", function(e) {
if (e.which == 1) { // if left mouse button is pressed
var posY=(e.pageY - 158)*(-1); // read the mouse Y-position
if(posY<0)
{
posY=0;
}
if(posY>180)
{
posY=180;
}
var ar = Math.round(posY/33); //Round number
var cssPosY = "-webkit-transform:rotate("+PosibleVal[ar]+"deg)";
$("#innerheater").attr("style", cssPosY); // change rotation
}
});
}
这里是示例的链接。(它仅适用于 chrome 和 safari)