Search code examples
jqueryjquery-1.6

jQuery 1.6.2 mouseup not firing


This code runs well with jQuery-1.3.2.min.js but doesn't run with jQuery-1.6.2.min.js .

$(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;
    }
});

how to make this code work on jQuery-1.6.2.min.js? any solution?


Solution

  • Perhaps this is what you wanted to do?

    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.");
    });