Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在js中如何旋转某些东西或抵消旋转?_Javascript_Android - Fatal编程技术网

Javascript 在js中如何旋转某些东西或抵消旋转?

Javascript 在js中如何旋转某些东西或抵消旋转?,javascript,android,Javascript,Android,我正在用JS编写一个时钟脚本,我在测试手柄动画时遇到了一个问题,因为我使用setInterval来制作动画,每次我旋转时,它不仅旋转手柄,而且旋转了所有东西,因为setInterval反复重复相同的代码,请帮助! 这是我的密码: function clockEffect(){ var d = new Date(); var h = d.getHours(); var l = 0; var lt = -100; setInterval(function(){ ctx.clearRect(0,0

我正在用JS编写一个时钟脚本,我在测试手柄动画时遇到了一个问题,因为我使用setInterval来制作动画,每次我旋转时,它不仅旋转手柄,而且旋转了所有东西,因为setInterval反复重复相同的代码,请帮助! 这是我的密码:

function clockEffect(){
var d = new Date();
var h = d.getHours();
var l =  0;
var lt =  -100;
setInterval(function(){
ctx.clearRect(0,0,400,400);
ctx.fillStyle="black";
ctx.fillRect(0,0,400,400);
ctx.strokeStyle="white";
ctx.fillStyle="white";
ctx.lineWidth="10";
ctx.strokeWidth
ctx.beginPath();
ctx.arc(200,200,200,200,0,360);
ctx.closePath();
ctx.stroke();
ctx.lineWidth="1";
ctx.font="60px Arial";
ctx.strokeText("12",168,60);
ctx.strokeText("3",340,210);
ctx.strokeText("9",30,210);
ctx.strokeText("6",184,360);

ctx.beginPath();
ctx.translate(200,200);
ctx.rotate(20*Math.PI/180);
ctx.moveTo(0,0);
ctx.lineTo(l,lt);
ctx.translate(-200,-200);
ctx.closePath();
ctx.stroke();
},40);
}
var called = clockEffect();

发布代码不会有什么坏处。你需要把代码放在你的问题中。您正在描述一个问题,这也需要代码,以便查看并找出问题。各位,我添加了我的代码:!但我还是没弄明白