伪代码:
if(onmousedown){
do{
移动
.....
}while(!onmouseup);
}

解决方案 »

  1.   

    下面一个例子,我是做的div,你把它换成img就行了:
    <html>
    <head>
    <title>test</title>
    <script language=javascript>
    function a(){
    if(document.all.canMove.value==1){c();}
    }
    function b(){
    document.all.canMove.value=0;
    alert("up");
    }
    function c(){
    var top=document.all.div1.style.top;
    top=top.substring(0,top.length-2);
    if(top>0){
    document.all.div1.style.top=top-1;
    setTimeout('a()',100); 
    }
    }
    function d(){
    document.all.canMove.value=1;
    a();
    }
    </script>
    </head>
    <body>
    <input type=button value="add" onmousedown="d()" onmouseup="b()">
    <div id=div1 style="position:absolute;top:100px;left:100px;width:100px;height:100px;background-Color:#cccccc"></div>
    <input type=hidden id="canMove" value="0">
    </body>
    </html>
      

  2.   

    这个简单点,可以看看呵呵~
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>图片测试</title>
    </head><body>
    <style>
    div{
    width:100px;
    height:100px;
    background:#FF0000;
    position:absolute;
    left: 28px;
    top: 17px;
    }</style>
    <script>
    i=10;
    function aa(){
    i++;
    d.style.left=i+"px";
    nn=setTimeout(aa,100);}
    function dd()
    {
    clearTimeout(nn);
    }
    </script>
    <div id="d"></div>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p><a href="#" onmousedown="aa()" onmouseout="dd()">测试</a></p>
    </body>
    </html>