背景移動
- Internet Explorer 6.0
- Internet Explorer 7.0
- Internet Explorer 8.0
- Mozilla Firefox 2.0
- Mozilla Firefox 3.0
- Google Chrome
- Safari 3.1
- Opera 9.5
- 背景移動 - 背景圖慢慢向一個指定方向移動。
- 語法總長度:841 字元
<script type="text/javascript"><!--
var background = "背景圖網址";
var speed = 50;
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (browserName != "Netscape" || browserVer >= 4.5) {
function moveback(movert,movedn,hPos,vPos) {
if (arguments[4]) document.body.style.backgroundImage = "url(\"" + arguments[4] + "\")";
if (arguments[5]) document.body.style.backgroundRepeat = arguments[5]
if (!isNaN(hPos)) {if ((movert!=0) && (hPos>0)) hPos=-100000; hPos += movert}
if (!isNaN(vPos)) {if ((movedn!=0) && (vPos>0)) vPos=-100000; vPos+= movedn}
document.body.style.backgroundPosition= hPos + " " + vPos
if (isNaN(hPos)) hPos = "\"" + hPos + "\""
if (isNaN(vPos)) vPos = "\"" + vPos + "\""
setTimeout("moveback("+movert+","+movedn+","+hPos+","+vPos+")",speed)}
moveback(1,1,0,0, background);}
// --></script>
- 在第 16 行修改移動方向
moveback(1,1,0,0, background);} 向右下角移動
moveback(0,1,0,0, background);} 向正下方移動
moveback(-1,1,0,0, background);} 向左下角移動
moveback(-1,0,0,0, background);} 向正左方移動
moveback(-1,-1,0,0, background);} 向左上角移動
moveback(0,-1,0,0, background);} 向正上方移動
moveback(1,-1,0,0, background);} 向右上方移動
moveback(1,0,0,0, background);} 向正右方移動
- 可修改第 2 行的背景圖網址
- 可修改第 3 行的數字,數字愈小移動速度愈快