このスクリプトを作成して、Web ページに回転可能なボタンを作成しました。それはかなりうまく機能しますが、機能を取り出したくありません。括弧内のコードを実行し続けます。どうすればそれを修正できますか?これは私が今持っているコードです。
マウスを押し下げてドラッグすると、値が変化します。しかし、今ではどこにでもあり、ボタンをクリックしてドラッグした場合にのみ発生する可能性があります.
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
}
});
}
HEREは例へのリンクです。(chrome と safari でのみ動作します)