我有這個下面的動畫:的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