【问题标题】:jQuery 1.6.2 mouseup not firingjQuery 1.6.2 mouseup 没有触发
【发布时间】:2011-10-24 22:32:42
【问题描述】:

这段代码在 jQuery-1.3.2.min.js 上运行良好,但在 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;
    }
});

如何让这段代码在 jQuery-1.6.2.min.js 上运行? 有什么解决办法吗?

【问题讨论】:

  • 任何错误信息?尝试使用萤火虫。
  • “不运行”是什么意思?
  • @mblase75 mouseup 没有触发

标签: jquery jquery-1.6


【解决方案1】:

也许这就是你想要做的?

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

【讨论】:

  • mouseup 只工作一次,当我点击第二次时它根本不起作用。
  • @Raju 是的,这就是 .one 方法应该做的。如果您不想这样,请改用.mouseup(function() ...)
  • mousemove 每次都在运行。
  • 那么对不起,我只是不清楚你想让脚本做什么。
  • 然后呢? mouseup 后,停止跟踪任何东西?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-14
  • 2013-09-10
  • 1970-01-01
相关资源
最近更新 更多