Explorar o código

修正3D模型越轉越快bug

nate %!s(int64=3) %!d(string=hai) anos
pai
achega
a94fa34f2d
Modificáronse 1 ficheiros con 7 adicións e 1 borrados
  1. 7 1
      script/js/3Dpic.js

+ 7 - 1
script/js/3Dpic.js

@@ -12,8 +12,14 @@
 
 	window.initThreeJS = init;
 
+	var id = null;
+
 	function init() {
 
+		if(id !== null){
+			cancelAnimationFrame(id);
+		}
+
 		canvas = document.getElementById("c");
 
 		const content = document.getElementById('content');
@@ -207,7 +213,7 @@
 	function animate() {
 
 		render();
-		requestAnimationFrame(animate);
+		id = requestAnimationFrame(animate);
 
 	}