JS實現讓網頁背景圖片斜向移動的方法
更新時間:2015年02月25日 11:07:10 作者:代碼家園
這篇文章主要介紹了JS實現讓網頁背景圖片斜向移動的方法,涉及javascript操作背景圖片特效的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了JS實現讓網頁背景圖片斜向移動的方法。分享給大家供大家參考。具體實現方法如下:
復制代碼 代碼如下:
<html>
<head>
<title>JS實現讓網頁背景圖片斜向移動</title>
<body background="images/changshi.ico">
<script language="Javascript">
<!--
function selectAll(theField){
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
}
//-->
</script>
<script language="Javascript">
<!--
var background = "images/changshi.ico";
var speed = 0;
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);
}
<head>
<title>JS實現讓網頁背景圖片斜向移動</title>
<body background="images/changshi.ico">
<script language="Javascript">
<!--
function selectAll(theField){
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
}
//-->
</script>
<script language="Javascript">
<!--
var background = "images/changshi.ico";
var speed = 0;
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>
</body>
</html>
希望本文所述對大家的javascript程序設計有所幫助。
相關文章
javascript getElementsByTagName
DC大神為早期不支持getElementsByTagName的瀏覽器寫的hack,當然與原生的不能同日而言,原生的用到緩存機制呢。2011-01-01基于JS實現彈出一個隱藏的div窗口body頁面變成灰色并且不可被編輯
這篇文章主要介紹了基于JS實現彈出一個隱藏的div窗口body頁面變成灰色并且不可被編輯的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-12-12JavaScript動態(tài)創(chuàng)建link標簽到head里的方法
這篇文章主要介紹了JavaScript動態(tài)創(chuàng)建link標簽到head里的方法,分別介紹了使用jQuery的方法、使用原生javascript方法與IE特有的createStyleSheet方法等,非常具有實用價值,需要的朋友可以參考下2014-12-12