2011-10-24 53 views
0

這段代碼在jQuery-1.3.2.min.js中運行良好,但不能在jQuery-1.6.2.min.js中運行。jQuery 1.6.2 mouseup沒有觸發

$(function(){ 
    $(document).mousedown(mouseUpAfterDrag); 

function mouseUpAfterDrag(e) { 

    /* You can record the starting position with */ 
    var start_x = e.pageX; 
    var start_y = e.pageY; 

    $().mousemove(function(e) { 
     /* And you can get the distance moved by */ 
     var offset_x = e.pageX - start_x; 
     var offset_y = e.pageY - start_y; 
    }); 

    $().one('mouseup', function() { 
     alert("This will show after mousemove and mouse released."); 
     $().unbind(); 
     $(document).mousedown(mouseUpAfterDrag); 
    }); 

    // Using return false prevents browser's default, 
    // often unwanted mousemove actions (drag & drop) 
    return false; 
    } 
}); 

如何使這段代碼在jQuery-1.6.2.min.js上工作? 任何解決方案?

+0

任何錯誤信息?嘗試使用螢火蟲。 –

+0

通過「不運行」你的意思是什麼,到底是什麼? – Blazemonger

+0

@ mblase75 mouseup沒有觸發 – Raju

回答

0

也許這就是你想要做的?

http://jsfiddle.net/mblase75/qtU4H/

var start_x, start_y, offset_x, offset_y; 

$(document).mousedown(function(e) { 
    start_x = e.pageX; 
    start_y = e.pageY; 
    // console.log("start = " + start_x + "," + start_y); 
}).mousemove(function(e) { 
    if (!isNaN(start_x)) { 
     offset_x = e.pageX - start_x; 
     offset_y = e.pageY - start_y; 
     // console.log("offset = " + offset_x + "," + offset_y); 
    } 
}).one('mouseup', function() { 
    alert("This will show after mousemove and mouse released."); 
}); 
+0

mouseup只能工作一次,當我點擊第二次時它根本不起作用。 – Raju

+0

@Raju是的,這就是'.one'方法應該做的。如果你不想要,可以使用'.mouseup(function()...)'代替。 – Blazemonger

+0

mousemove每次都在運行。 – Raju