我是在一个图片上的onmousedown上使用
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP)
但却无效, 在IE中使用的Obj.setCapture();才有效

解决方案 »

  1.   

    换成addEventListener试一下!!function scrollMe(event)
    {
      var st = event.currentTarget.scrollTop + (event.detail * 12);
      event.currentTarget.scrollTop = st < 0 ? 0 : st;
      event.preventDefault();
    }
    if (document.body.addEventListener) {
      var divs = document.getElementsByTagName('DIV');
      for (var d in divs) {
        if (divs[d].className && divs[d].className == 'tekstveld') {
          try {
    divs[d].addEventListener('DOMMouseScroll', scrollMe, false);
          } catch (ex) {}
        }
      }
     }
      

  2.   

    //试一下这个例子吧,在Firefox可以运行
    也使用了captureEvents<html>
    <head>
    <title> Drag Demo 1 </title>
    <style type="text/css">
    <!--
    #drag{
    width:100px;
    height:20px;
    background-color:#eee;
    border:1px solid #333;
    position:absolute;
    top:30px;
    left:200px;
    text-align:center;
    cursor:default;
    }
    //-->
    </style>
    <script type="text/javascript">
    <!--
    window.onload=function(){
    drag(document.getElementById('drag'));
    };function drag(o){
    o.onmousedown=function(a){
    var d=document;if(!a)a=window.event;
    var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
    if(o.setCapture)
    o.setCapture();
    else if(window.captureEvents)
    window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); d.onmousemove=function(a){
    if(!a)a=window.event;
    if(!a.pageX)a.pageX=a.clientX;
    if(!a.pageY)a.pageY=a.clientY;
    var tx=a.pageX-x,ty=a.pageY-y;
    o.style.left=tx;
    o.style.top=ty;
    }; d.onmouseup=function(){
    if(o.releaseCapture)
    o.releaseCapture();
    else if(window.captureEvents)
    window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
    d.onmousemove=null;
    d.onmouseup=null;
    };
    };
    }
    //-->
    </script>
    </head><body>
    <div id="drag">drag me<div>
    </body>
    </html>
      

  3.   

    不明, window.captureEvents跟addEventListener有什么关系呀?
      

  4.   

    clare2003(忘情火)我也知道那个例子,正常window.captureEvents是有效的, 但如果事件发生在图片上好像没效, 你可以试试
      

  5.   

    改称这样在FireFox和IE下通过
    图片可以拖动!
    =============================
    <html>
    <head>
    <title> Drag Demo 1 </title>
    <style type="text/css">
    <!--
    #drag{
    width:100px;
    height:20px;
    background-color:#eee;
    border:1px solid #333;
    position:absolute;
    top:30px;
    left:200px;
    text-align:center;
    cursor:default;
    }
    //-->
    </style>
    <script type="text/javascript">
    <!--
    window.onload=function(){
    drag(document.getElementById('drag'));
    };function drag(o){
    o.onmousedown=function(a){
    var d=document;if(!a)a=window.event;
    var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
    if(o.setCapture)
    o.setCapture();
    else if(window.captureEvents)
    window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); d.onmousemove=function(a){
    if(!a)a=window.event;
    if(!a.pageX)a.pageX=a.clientX;
    if(!a.pageY)a.pageY=a.clientY;
    var tx=a.pageX-x,ty=a.pageY-y;
    o.style.left=tx;
    o.style.top=ty;
    }; d.onmouseup=function(){
    if(o.releaseCapture)
    o.releaseCapture();
    else if(window.captureEvents)
    window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
    d.onmousemove=null;
    d.onmouseup=null;
    };
    };
    }
    //-->
    </script>
    </head><body>
    <img id="drag" src="http://community.csdn.net/logo/images/cc2e.jpg">
    </body>
    </html>
      

  6.   

    呵呵, 不行呀clare2003(忘情火),你自己试试吧, 它的效果明显示不行的, 当鼠标一按下拖动时就会变成禁止拖动的鼠标, 表示捕捉不了事件,到你放出鼠标时才有效, IE就可以
      

  7.   

    我也遇到同样的问题了,clare2003(忘情火)的方法确实不行,关注