【发布时间】:2018-04-20 08:33:06
【问题描述】:
我想把按钮放在可移动元素js中;我不知道如何开始,我是初学者,我无法找到解决方案。
如何在可移动的 js 元素中插入带有函数调用的按钮?
这里是一个例子:enter image description here
还有一些js代码:
var pos = $('#center').position(),
radiusSat = $('#sat1').width() * 0.5,
radius = $('#center').width() * 0.5,
cx = pos.left + radius,
cy = pos.top + radius,
x, y, angle = 0, angles = [],
spc = 360 / 5,
deg2rad = Math.PI / 180,
i = 0;
for(;i < 5; i++) {
angles.push(angle);
angle += spc;
}
`/// space out radius`
radius += (radiusSat + 10);
loop();
function loop() {
for(var i = 0; i < angles.length; i++) {
angle = angles[i];
x = cx + radius * Math.cos(angle * deg2rad);
y = cy + radius * Math.sin(angle * deg2rad);
$('#sat' + i).css({left:x - radiusSat, top:y - radiusSat});
angles[i] = angles[i] + 1;
if (angles[i] > 360) angles[i] = 0;
}
requestAnimationFrame(loop);
}
【问题讨论】:
-
您想在单击#sat div 时添加按钮还是预期的功能是什么?
-
我想在这个移动的 js 结构中创建移动按钮。每次点击按钮时,另一个函数应该生成随机数。
标签: javascript html css frontend