js 實現靜態圖片動起來
阿新 • • 發佈:2019-01-02
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>圖片移動顯示</title>
<style type="text/css">
#picture
{
width: 500px;
height: 500px;
text-align: center;
}
#picture img
{
height: 450px;
width:400px;
}
</style>
<script type="text/javascript">
var n=1;
function move()
{
var pic=document.getElementById("myimg");/*獲取到圖片物件*/
pic.src="images/"+((n++%7)+1)+".png";/*獲取到圖片物件的路徑*/
}
window.setInterval("move()", 500);;/*每隔500毫秒執行move()函式*/
</script>
</head>
<body>
<div id="picture"><img src="images/1.png" id="myimg"></div>
</body>
</html>
<html>
<head>
<title>圖片移動顯示</title>
<style type="text/css">
#picture
{
width: 500px;
height: 500px;
text-align: center;
}
#picture img
{
height: 450px;
width:400px;
}
</style>
<script type="text/javascript">
var n=1;
function move()
{
var pic=document.getElementById("myimg");/*獲取到圖片物件*/
pic.src="images/"+((n++%7)+1)+".png";/*獲取到圖片物件的路徑*/
}
window.setInterval("move()", 500);;/*每隔500毫秒執行move()函式*/
</script>
</head>
<body>
<div id="picture"><img src="images/1.png" id="myimg"></div>
</body>
</html>