jquery页面加载后背景图每隔3秒换一次
1个回答
展开全部
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>定时更换背景</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
//图片数组
var sArr =['http://pic11.nipic.com/20101208/6370412_175553023065_2.jpg','http://pic28.nipic.com/20130422/7278647_200808529196_2.jpg','http://img01.tooopen.com/Downs/images/2010/4/16/sy_20100416154224949419.jpg'];
//定时更换背景
setInterval(function(){
$("body").css("backgroundImage","url("+sArr[fRandomBy(0,2)]+")");
},3000); //单位毫秒
//设定随机数的范围
function fRandomBy(under, over){
switch(arguments.length){
case 1: return parseInt(Math.random()*under+1);
case 2: return parseInt(Math.random()*(over-under+1) + under);
default: return 0;
}
}
})
</script>
</head>
<body style="background-image:url(http://pic11.nipic.com/20101208/6370412_175553023065_2.jpg)">
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询