8-1.html

来自「JavaScript经典实例教程代码」· HTML 代码 · 共 56 行

HTML
56
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>picmove</title>
<META http-equiv="content-type" CONTENT="text/html;charset=gb2312">
<META NAME="Author" CONTENT="CZH;czh44@sohu.com">
</head>
<script>
theX=0;
theY=0;
to=0;
le=0;
step=9;
inter=100;
ifNN4=(navigator.appName=="Netscape"&&parseInt(navigator.appVersion)==4);
ifNN6=(navigator.appName=="Netscape"&&parseInt(navigator.appVersion)==5);
function movePic()
{
var layImg=(ifNN4)?document.layImg:document.getElementById('layImg').style;
	if(theX-le>-30||theX-le<-40)
	{
	le+=step*((theX-le>-30)?1:-1);
	layImg.left=le;
	}
	if(theY-to>80||theY-to<70)
	{
	to+=step*((theY-to>80)?1:-1);
	layImg.top=to;
	}
	setTimeout('movePic()',inter);
}
function getPos(e)
{
	if(ifNN4||ifNN6)
	{
	theX=e.pageX;
	theY=e.pageY;
	}
	else
	{
	theX=document.body.scrollLeft+event.clientX;
	theY=document.body.scrollTop+event.clientY;
	}
}
if(ifNN4||ifNN6)
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=getPos;
</script>
<body onload="movePic()"> 
<div id="layImg" style="position:absolute;z-index:10">
<img src="pic1.gif" alt="study in Canada">
</div>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?