2012-02-29 53 views

回答

4

所有jQueryUI的事件提供event作为回调参数

$(ui).offset() 

可有趣

$(".selector").selectable({ 
    stop: function(event, ui) { 
     alert(event.pageX) ; 
    } 
}); 

良好的学习技巧与jQueryUI的是记录eventui控制台上的一些事件。特别是ui。给你一个很好的感觉,可以使用什么

0

沿着这些线怎么样?

var curX = 0; 
var curY = 0; 

$(document).mousemove(function(e) 
{ 
    curX = e.pageX; curY = e.pageY; 
}); 

$(".selector").selectable({ 
    stop: function(event, ui) { console.log(curX+"/"+curY); } 
}); 

,也:到look at.

0

这会有帮助吗?再加上其他两个答案,如果你只是做了console.log(e),你可以找到很多有关该事件的信息。通过这些信息,我发现pageX和pageY信息存储在originalEvent下。

    console.log(e.originalEvent.pageX); 
        console.log(e.originalEvent.pageY); 

此外,当你选择一个项目,并有自己的Chrome开发者工具打开并查看元素,一个div中加入一类的“UI可选择的辅助性”,它计算的顶部和左侧位置你的鼠标。

1

在上个月,我决定我需要一个可靠的方法来检查鼠标定位,并使用jquery轻松获得鼠标悬停。以下是我使用的代码,我认为它会解决您的问题。

var mouse = { 
    mouseX: null, 
    mouseY: null, 
    init: function() { 
     $(document).bind('mousemove', function(event) { 
      mouse.mouseX = event.pageX; 
      mouse.mouseY = event.pageY; 
     }); 
    }, 
    isOver: function($element) { 
     $elementPosition = $($element).offset(); 
     $elementWidth = $($element).width(); 
     $elementHeight = $($element).height(); 
     $returnValue = true; 
     if (mouse.mouseX !== null) { 
      if (mouse.mouseX < $elementPosition.left) { $returnValue = false; } 
      if (mouse.mouseY < $elementPosition.top) { $returnValue = false; } 
      if (mouse.mouseX > $elementPosition.left + $elementWidth) { $returnValue = false; } 
      if (mouse.mouseY > $elementPosition.top + $elementHeight) { $returnValue = false; } 
     } 
     return $returnValue; 
    } 
} 

你只需要开枪domready中初始化,然后就可以得到当前鼠标在任何时间坐标和你可以找出是否鼠标在一个特定的元素容易。

// Init 
jQuery(document).ready(function() { 
    mouse.init(); 
}); 

//Getting Positions 
var mouseX = mouse.mouseX; 
var mouseY = mouse.mouseY; 

// Determining Mouseover 
if (mouse.isOver($('#elementId'))) { 
    alert('Is over'); 
} 
+0

不错的代码,但OP是问如何做到这一点在jQuery UI可选的停止事件。 – 2012-02-29 18:09:34