博客头部的随机变化的封面背景,通过javascript和CSS一起实现起来并不难,下面是相应的javascript代码:
下面这段代码放在html的头部head中,
<script language="JavaScript" type="text/javascript" >
var imgNameList=new Array();
imgNameList.push("/1000x226_01.JPG");
imgNameList.push("/1000x226_02.JPG");
imgNameList.push("/1000x226_03.JPG");
imgNameList.push("/1000x226_04.JPG");
imgNameList.push("/1000x226_05.JPG");
imgNameList.push("/1000x226_06.JPG");
</script>
下面这段放在html的body中,
<script>
document.write("<style>#aaa {background: url("+imgNameList[parseInt(Math.random()*imgNameList.length)]+");}<\/style>");
</script>
接下来对我的那几张图片进行介绍一下,拍得比较满意就贴出来当封面背景照片:
- 帕米尔高原 昆仑山 新疆
- 丙察察线出目诺村的第一个山口森林 西藏
- 羊卓雍错 西藏
- 天山 哈希勒根达坂 新疆
- 南迦巴瓦峰 西藏
- 白居寺后山 江孜 西藏