Javascript 影片移動

請問我要用javascript 讓影片可以移動 由左向右移(類似跑馬燈) 我要怎麼寫??

以下是我程式碼:

<!DOCTYPE html>

<html>

<head>

<title>HTML3</title>

<style type="text/css">

#video1{

position:absolute;

left:20px;

top:20px;

}

#run{

position:absolute;

left:20px;

top:250px;

}

</style>

<script type="text/javascript">

function timer()

{

timer = setTimeout("running()",1000);

}

function running()

{

document.getElementById('video1').style.left=x;

var x=20;

for (var i=0;i<500;i++)

{

x=x+1;

}

}

</script>

</head>

<body>

<div id="video1"><video width="200" height="200" controls="controls">

<video width="200" height="200" controls="controls">

<embed src="13.wmv" width="200px" height="200px"></embed>

</video></div>

<div id="run"><input type="button" onclick="running();" value="影片移動"></div>

</body>

</html>

1 Answer

Rating
  • 9 years ago
    Favorite Answer

    <!DOCTYPE html>

    <html>

    <head>

    <title>HTML3</title>

    <style type="text/css">

    #video1{

    position:absolute;

    left:20px;

    top:20px;

    }

    #run{

    position:absolute;

    left:20px;

    top:250px;

    }

    </style>

    <script type="text/javascript">

    window.onload = function(){

    el = document.getElementById('video1')

    begin = el.style.left;

    x = 0;

    }

    function running(){

    x++;

    el.style.left = begin +x + 'px';

    if (x <=500) setTimeout(running,10); }

    </script>

    </head>

    <body>

    <div id="video1">

    <video width="200" height="200" controls="controls">

    <embed src="13.wmv" width="200px" height="200px"></embed>

    </video>

    </div>

    <div id="run"><input type="button" onclick="running();" value="影片移動">

    </body>

    </html>

    以上請參考

    div是這樣移動的

    但不確定你的video標籤這樣用是否正確

Still have questions? Get your answers by asking now.