日期:2014-05-16 浏览次数:20511 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></HEAD>
 <BODY style="height:800px;">
    <div id="testDiv" style="width:200px; height:200px; background:#f00; position:absolute; cursor:move"></div>
<script type="text/javascript">
var start    =
(function(){
        var i,    // count
            o,    // HTML DOM
            x,y;
        
        function moving(e)
        {
            if(i++^6)//like if(!(i++===6))
                return;
            o.style.left=(e.screenX-x)+'px';
            o.style.top=(e.screenY-y)+'px';
            i=0;
        }
        function end(e)
        {
            if(window.addEventListener){
                    window.document.removeEventListener('mousemove',moving,false);
                    document.removeEventListener('mouseup',arguments.callee,false);
            }else{
                        window.document.detachEvent('onmousemove',moving);
                        window.document.detachEvent('onmouseup',arguments.callee);
            }
                
            window.document.body.focus()    // ff 3.0
        }
        
        return function(e,d)
        {
            i    =    0;
            x    =    e.screenX-d.offsetLeft;
            y    =    e.screenY-d.offsetTop;
            o    =    d;
            
            if(window.addEventListener){
                window.document.addEventListener