使用提示
可以拖动的图片
演示效果:请用鼠标拖动图片
代码提示:按下面的说明和注释复制代码
一:修改<body***>中的内容,将下面的代码加入原<body***>中 onload="init()" 二:将下面的代码复制到〈BODY〉与〈/BODY〉中 <SCRIPT language=JavaScript> drag = 0 move = 0 function init() { window.document.onmousemove = mouseMove window.document.onmousedown = mouseDown window.document.onmouseup = mouseUp window.document.ondragstart = mouseStop } function mouseDown() { if (drag) { clickleft = window.event.x - parseInt(dragObj.style.left) clicktop = window.event.y - parseInt(dragObj.style.top) dragObj.style.zIndex += 1 move = 1 } } function mouseStop() { window.event.returnValue = false } function mouseMove() { if (move) { dragObj.style.left = window.event.x - clickleft dragObj.style.top = window.event.y - clicktop } } function mouseUp() { move = 0 } </SCRIPT> <div id="block1" onmouseout="drag=0" onmouseover="dragObj=block1; drag=1;" style="height: 90; left: 200; position: absolute; top: 200; width: 90"> <dd> <!-- 改变下面的图像名称和宽度、高度--> <img alt border="0" src="13.gif" width="146" height="100"> </dd> </div>
使用提示
返回目录