Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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 css翻译不';我不能处理数学函数_Javascript_Jquery - Fatal编程技术网

Javascript css翻译不';我不能处理数学函数

Javascript css翻译不';我不能处理数学函数,javascript,jquery,Javascript,Jquery,我正在尝试将4个矩形框转换为具有sin/cos函数的矩形框。但它在chrome/firefox中不起作用。然而在IE中,它是有效的。下面给出了代码和示例,您可以在中看到演示 (函数(){ 变量圆=$(“.circle”), circleChild=$(“.circle child”,circle), circleChildLength=circleChild.find(“li”).length, IsDraged=false, 速度=5, 角度=[], 初始距离=0, 总距离=150; 函数mo

我正在尝试将4个矩形框转换为具有sin/cos函数的矩形框。但它在chrome/firefox中不起作用。然而在IE中,它是有效的。下面给出了代码和示例,您可以在中看到演示

(函数(){
变量圆=$(“.circle”),
circleChild=$(“.circle child”,circle),
circleChildLength=circleChild.find(“li”).length,
IsDraged=false,
速度=5,
角度=[],
初始距离=0,
总距离=150;
函数moveChildCircles(){
初始距离+=速度;

如果(initialDistance>=totalDistance | | initialDistance由于计算分数像素的数学运算,CSS更改似乎不起作用。请尝试在像素计算中使用
math.round

$(this).css("transform", "translate(" + Math.round(initialDistance*Math.cos(angles[i])) + "px," + Math.round(initialDistance*Math.sin(angles[i])) + "px)");

我得出了相同的答案,但使用了Math.floor()。我们可能应该将差异分开,然后使用
Math.round()
。哦,伙计,你太棒了。我在html5画布上这样做,它在那里工作。但是当我使用DOM时,浏览器就忽略了它。这意味着css translate不支持分数。顺便说一句,我想我们也可以使用toFixed()
$(this).css("transform", "translate(" + Math.round(initialDistance*Math.cos(angles[i])) + "px," + Math.round(initialDistance*Math.sin(angles[i])) + "px)");