我有這樣的代碼:如何讓圖像從左側0,0位置向右側移動到右側?
<script type="text/javascript">
var animate, left=0, imgObj=null;
function init(){
imgObj = document.getElementById('myImage');
imgObj.style.position= 'absolute';
imgObj.style.top = '240px';
imgObj.style.left = '-300px';
imgObj.style.visibility='hidden';
moveRight();
}
function moveRight(){
left = parseInt(imgObj.style.left, 10);
if (10 >= left) {
imgObj.style.left = (left + 5) + 'px';
imgObj.style.visibility='visible';
animate = setTimeout(function(){moveRight();},20);
} else {
stop();
}
}
function stop(){
clearTimeout(animate);
}
window.onload = function() {init();};
</script>
<img id="myImage" src="http://newsxpressmedia.com/files/radar-simulation-files/radar007339.Gif" style="margin-left:170px;" />
什麼它在屏幕的從左側到中心中間移動一個圖像。 但我想要它做的是將圖像從左上角0,0移動到右側的結尾到右上邊界,並不停止,但圖像將開始再次從右側移動到左邊。
我從來沒有理解這個px值。現在它設置爲240並且離開-300。我試圖將其更改爲0和0,但它沒有放在左上角,圖像根本沒有移動。
如何更改代碼,以便它將開始將圖像從左上角移動到右上角,以及如何添加更多圖像,以便像幻燈片一樣從左向右不停地移動圖像?
friedi和我如何讓它重新開始當它到達右側時,從左向右移動?我希望它不停地移動。 – 2014-11-21 19:43:56
我在第二個問題中加入了答案 – friedi 2014-11-21 19:45:28
friedi它工作得很好。我不確定是否要問這裏,但我有兩個子問題請:我有一個幻燈片的圖像,但由於slidingshow是在屏幕的中間頂部,運動圖像並沒有表明它移動它。我怎樣才能讓運動圖像/代碼將幻燈片向下推到屏幕中間,這樣兩張幻燈片之間會有一些空間?這是我的html代碼:http://jsfiddle.net/o4ndyzj8/1/你可以在我的網站上直接看到它:http://newsxpressmedia.com/SlideShow.php,這是html代碼:http ://pastebin.com/nsNvZDs2 – 2014-11-21 19:59:09