【发布时间】:2015-07-08 02:34:06
【问题描述】:
我的网站上目前有一个停滞的图像:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/stylesheets/normalize.css" media="all" rel="stylesheet" />
<link href="/stylesheets/master.css" media="all" rel="stylesheet" />
<script>
window.onload = function () {
var images = [],
i=1, indexImages = true,
prefix = '../image/',
extension = '.jpg';
while (indexImages) {
var a = new XMLHttpRequest(); a.open('GET', prefix+i+extension, false); a.send();
if (a.status != 404) { i += 1; images.push(prefix+i+extension); } else {
indexImages = false;
localStorage['backgroundIndex'] = !localStorage['backgroundIndex']?0:+localStorage['backgroundIndex']+2>images.length?0:+localStorage['backgroundIndex']+1;
document.body.style.backgroundImage = 'url(' + images[+localStorage['backgroundIndex']] + ')';
}
}
}
</script>
<style>
body {
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-color: black;
border-bottom: 8px solid #7D8A28;
}
</style>
</head>
<body>
<section id="card">
</section>
</body>
</html>
只是我希望每次页面刷新时它都是不同的图像,所以它会自动更改为 2.jpg、3.jpg、10.jpg 等。 (有数百种可供选择)
有人可以帮我解决吗?我不太擅长这个,这是我的第一个网站。
谢谢。
【问题讨论】:
-
是的,但是上面写着:'url(img/rainbow.jpg)', 'url(img/chickens_on_grass.jpg)' 'url(img/cattle_on_pasture.jpg)' 'url(img /csa_bundle.jpg)' - 我确实有数百个。
标签: javascript php html css web