好吧,我在网上看到过很多这方面的问题,但似乎很多问题都在使用PHP,ASP,JQUERY和其他语言。对于我来说,我只对CSS和Java Script有点熟悉,那是我只知道的语言。那么有人可以向我展示一些关于CSS和Java Script的代码吗?如何每次点击每个链接或网址时更改我网站的背景图片?
无论如何,我也有兴趣在网站上的背景,将改变每一个刷新!
在此先感谢!
嘿,我发现了示例代码,它是完美的工作!
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function changeImg(imgNumber) {
var myImages = ["Background/Background.jpg", "Background/Background2.jpg", "Background/Background3.jpg", "Background/Background4.jpg", "Background/Background5", "Background/Background6", "Background/Background7"];
var imgShown = document.body.style.backgroundImage;
var newImgNumber =Math.floor(Math.random()*myImages.length);
document.body.style.backgroundImage = 'url('+myImages[newImgNumber]+')';
}
window.onload=changeImg;
</script>
<style type="text/css">
.bg {background-attachment:fixed; background-repeat: no-repeat; background-position:top right;}
</style>
</head>
<body class="bg">
<p>Some text</p>
<!-- put a lot text lines here to see that the background stays fixed. -->
<p>Some text</p>
</body>
</html>
[你尝试过什么?](http://www.whathaveyoutried.com/) –
如果使用刷新一个新的形象,每次,比你杀死你的网站美+你讨厌你的用户通过增加页面加载时间 –
嗨! Alien先生我的网站通过局域网运行,我的意思是它在共享网络或计算机内运行。 :D所以基本上页面加载不是一个问题。这就是我对这项工作感兴趣的原因。 – Jayseer