我有这个下面的动画:的Javascript振荡
<!DOCTYPE HTML>
<html>
<head>
<style>
.example_path {
position: relative;
overflow: hidden;
width: 530px;
height: 30px;
border: 3px solid #000;
}
.example_path .example_block {
position: absolute;
background-color: blue;
width: 30px;
height: 20px;
padding-top: 10px;
text-align: center;
color: #fff;
font-size: 10px;
white-space: nowrap;
}
</style>
<script>
function move(elem) {
var left = 0
function frame() {
left+=10 // update parameters
elem.style.left = left + 'mm' // show frame
if (left == 10000) // check finish condition
clearInterval(id)
}
var id = setInterval(frame, 1) // draw every 1ms
}
</script>
</head>
<body>
<div onclick="move(this.children[0])" class="example_path">
<div class="example_block"></div>
</div>
</body>
</html>
正如你看到的,蓝色块移动,如果它跨越它的矩形。我如何有蓝色块附近摆动的矩形边框来来回回保持速度恒定的整个...
(在我的情况下,速度为10米/秒又名以10mm/MS)
请添加一些更多的细节,你需要从这段代码? –
您是否复制了代码并将其粘贴到文本编辑器中,只需尝试一下并告诉我会发生什么情况?该块越过右边界的权利? @ZaheerAhmed – tenstar
这是一个[JSFiddle](http://jsfiddle.net/d5y6w/)的问题。我建议为未来的问题添加一个 – SpenserJ