首页论坛图片汽车百科旅游美食诗词英语IT留学移民电影下载Archiver站点地图
当前位置: 易飞网 >> 首页 >> 站长学院 >> 网页特效 >> 正文

可以拖动的图片

说明:按下面的说明和注释复制代码

效果

 

代码:

一:修改<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="http://www.eeffee.com/attachments/2007/07/29/1_200707292159161.gif" width="200" height="100"> </dd> </div>