Javascript 如何在不旋转图像的情况下以圆周运动移动图像?
我需要有一个在我的网站上的太阳和月亮的图像,这将是,为一天的大部分时间被隐藏,但当它是他们的时间显示,他们将在一个圆周运动,从左开始,到右结束 我有一个代码,上面写着白天或晚上要实现多少百分比,我只需要知道如何在不旋转图像的情况下以圆周运动移动图像。css部分:Javascript 如何在不旋转图像的情况下以圆周运动移动图像?,javascript,html,Javascript,Html,我需要有一个在我的网站上的太阳和月亮的图像,这将是,为一天的大部分时间被隐藏,但当它是他们的时间显示,他们将在一个圆周运动,从左开始,到右结束 我有一个代码,上面写着白天或晚上要实现多少百分比,我只需要知道如何在不旋转图像的情况下以圆周运动移动图像。css部分: 将css位置设置为绝对 根据三角学设置x和y坐标(css顶部和左侧) 三角学: 基本上你想转半圈,π度为0%,0度为100%,所以这就像得到圆坐标一样(即x=中心+半径*cos(角度)),但唯一复杂的部分是你需要反转角度:π*(1%)
var body = document.getElementsByTagName("body")[0],
radius = 100, // Some radius here
max = 50; // max number of generations we want (half a circle)
for (var i = 1; i <= max * 2; i++) {
var div = document.createElement("div"),
angle = Math.PI * (i / max);
div.style.backgroundColor = "#000";
div.style.borderRadius = div.style.height = div.style.width = "8px";
div.style.left = ((Math.sin(angle) * radius) + radius) + "px";
div.style.position = "absolute";
div.style.top = ((Math.cos(angle) * radius) + radius) + "px";
body.appendChild(div);
}
var body=document.getElementsByTagName(“body”)[0],
半径=100,//这里有些半径
最大值=50;//我们想要的最大代数(半圆)
对于(var i=1;据我所知,这与php无关,因此使用javascript和htmlWell重新标记所有计算都是在php中完成的,以找出用户日出和日落的时间,并计算他们在夜间或白天的百分比,因此我想我必须告诉图像需要在哪里也通过PHP?我无法区分语言,这是Javascript还是PHP,我如何使用它来编辑CSS/图像?如果你无法区分语言,那么我认为你可能需要一本初学者书籍或课程,而不是具体的编程问题…如果你不致力于PHP,我建议代码是Javascript(注意,它使用屏幕的宽度和高度,这在服务器端是不可用的)。您可能可以在PHP中执行相同的计算,并使用百分比而不是像素坐标,例如x=50+33*cos(角度),但请记住,要使用css绝对位置和百分比,您需要容器元素为position:relative。
var body = document.getElementsByTagName("body")[0],
radius = 100, // Some radius here
max = 50; // max number of generations we want (half a circle)
for (var i = 1; i <= max * 2; i++) {
var div = document.createElement("div"),
angle = Math.PI * (i / max);
div.style.backgroundColor = "#000";
div.style.borderRadius = div.style.height = div.style.width = "8px";
div.style.left = ((Math.sin(angle) * radius) + radius) + "px";
div.style.position = "absolute";
div.style.top = ((Math.cos(angle) * radius) + radius) + "px";
body.appendChild(div);
}