html5更改背景图像间隔时间 [英] html5 change background image interval time

查看:96
本文介绍了html5更改背景图像间隔时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在间隔时间更改身体背景图像,例如,每10秒应更改背景图像。
可以使用html5吗?

谢谢

How can i change body background image at interval time, for example, every 10 seconds should change the background image. it is possible with html5?
Thanks

推荐答案

你可以使用javascript函数这个并在该函数本身中使用SetTimeOut,它将在指定的时间间隔后调用相同的函数。

You can use a javascript function for this and use the SetTimeOut in that function itself which will call the same function after the specified time interval.

请尝试以下操作:

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
var imageID=0;
function changeimage(every_seconds){
    //change the image
    if(!imageID){
        document.getElementById("myimage").src="http://www.all-freeware.com/images/full/38943-nice_feathers_free_screensaver_desktop_screen_savers__nature.jpeg";
        imageID++;
    }
    else{if(imageID==1){
        document.getElementById("myimage").src="http://www.hickerphoto.com/data/media/186/flower-bouquet-nice_12128.jpg";
        imageID++;
    }else{if(imageID==2){
        document.getElementById("myimage").src="http://www.photos.a-vsp.com/fotodb/14_green_cones.jpg";
        imageID=0;
    }}}
    //call same function again for x of seconds
    setTimeout("changeimage("+every_seconds+")",((every_seconds)*1000));
}
</script>
</head>

<body style='background:black;' onload='changeimage(2)'>
<div style='position:absolute;width:100%;height:100%;left:0px;top:0px;' align='center'><img width='300px' height='250px' id='myimage' src='http://www.photos.a-vsp.com/fotodb/14_green_cones.jpg'/></div>
</body>

</html>

这篇关于html5更改背景图像间隔时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆