我有一个小工件。
HTML:
<div id="it">X</div>
CSS:
#it {
background: blue;
width: 40px;
text-align: center;
color: white;
padding: 10px 0;
border: solid 1px black;
border-radius: 25px;
position: absolute;
left: 100px;
top: 100px;
}
JS:
$('#it').animate({
left: '+=100',
top: '+=100'
}, 400, function() {
$(this).animate({
top: '-=100'
}, 400, function() {
$(this).animate({
left: '-=100',
top: '+=100'
}, 400, function() {
$(this).animate({
top: '-=100'
}, 400);
});
});
});
上述所有内容都放在这个jsfiddle中
我需要帮助:
- 循环 JS。此外,我几乎可以肯定可以做一些事情来简化重复的嵌套代码。
- 使运动平稳。即,使物体以单条曲线飞行,沿着“倾斜的 8”形状,而不是 4 条直线。
- 如果可能,摆脱 JS 并用 CSS3 替换它。
我的项目也不一定需要,但如果有一种方法可以沿途旋转对象,使其始终面向它前进的方向,那就太棒了。就像您从上方观看赛车一样。