87,994
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
</head>
<body>
<img id="img1" style="z-index: -1;position: absolute;left: 0;top: 0;" />
<script>
+ function() {
//设置初始化设置
$("#img1").attr("src", "./img/" + getRandomSrc() + ".jpg"); //获取同级目录中的img文件内的jpg图片
var width = window.innerWidth > 0 ? window.innerWidth : document.body.clientWidth; //宽度
var height = window.innerHeight > 0 ? window.innerHeight : document.body.clientHeight; //高度
$("#img1").attr("width", width);
$("#img1").attr("height", height);
}();
function getRandomSrc() {
var rnd = Math.ceil(Math.random() * 7);
return rnd;
}
</script>
</body>
</html>
<script>
$(function() {
getRandomSrc();
setInterval(getRandomSrc, 6000);
});
function getRandomSrc() {
var rnd = Math.ceil(Math.random() * 7);
//设置初始化设置
$("#img1").attr("src", "./img/" + rnd + ".jpg"); //获取同级目录中的img文件内的jpg图片
var width = window.innerWidth > 0 ? window.innerWidth : document.body.clientWidth; //宽度
var height = window.innerHeight > 0 ? window.innerHeight : document.body.clientHeight; //高度
$("#img1").attr("width", width);
$("#img1").attr("height", height);
}
</script>