Pārlūkot izejas kodu

Zoom controls with mousewheel

Iñigo Valentin 12 gadi atpakaļ
vecāks
revīzija
bbc5d15015
1 mainītis faili ar 22 papildinājumiem un 0 dzēšanām
  1. 22 0
      script/ObJS.js

+ 22 - 0
script/ObJS.js

@@ -398,6 +398,28 @@ function initCanvas(){
 		draw();
 		return false;
 	}
+	
+	canvas.addEventListener('mousewheel',function(event){
+		if (event.wheelDelta > 0)
+			zoom("-");
+		else 
+			zoom("+");
+		return false;
+	}, false);
+}
+
+/********************************************************************
+ * Function that changes the scale variable, witch results in a     *
+ * zoom in or zoom out effect.                                      *
+ * #parameters: none                                                *
+ * #return: nothing                                                 *
+ ********************************************************************/
+function zoom(dir){
+	if (dir == "+")
+		scale = Math.round(scale * 1.2);
+	if (dir == "-")
+		scale = Math.round(scale * 0.8);
+	draw();
 }
 
 /********************************************************************