I wrote this script to make a turnable button in a web page. It works pretty good but it doesn't want to get out the function. It keeps running the code inside the brackets. Any idea how I can fix that? This is the code i have now.
If you press your mouse down and you drag the value will change. But now it's everywhere and it may only happen if you click on the button and than drag.
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 is a link to the example.(It works only in chrome and safari)