我有一个轮播基于:
http://nooshu.com/explore/jquery-iphone-animation/
当您在抓取和拖动过程中时,您很容易选择文本。如果面板中有链接,我会收到悬停消息等...
我想禁用所有这些,因此当您在拖动过程中时,其余的交互将被禁用。
想法?
最佳答案
像这样创建一个样式类:
.unselectable {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
-ms-user-select : none
}
然后稍微修改 Javascript 以在 mousedown 时分配此类。因此,从那个未更改的脚本来看,它看起来像这样。
jQuery(function($){
//Initialise
iPhoneAnimation.init();
//Mouse down bind move event
$(".content-box").bind("mousedown", function(e){
$(this).bind("mousemove", iPhoneAnimation.moveInfo);
$(this).addClass("unselectable"); // <-- ADD THIS
});
//Unbind mouse event
$(".content-box").bind("mouseup", function(e){
var $this = $(this);
$this.unbind("mousemove", iPhoneAnimation.moveInfo);
//Animate the panel
iPhoneAnimation.panelAnimate($this);
//Reset the private var
iPhoneAnimation.resetVars();
$(this).removeClass("unselectable"); // <-- AND ADD THIS
});
});
要禁用悬停,您需要像这样取消绑定(bind) mousedown
上的事件:
$(this).unbind('mouseenter mouseleave');
然后如上所述在 mouseup
上重新绑定(bind)它们。
关于javascript - 在 JQuery 插件中拖动元素时禁用悬停、文本选择等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7327627/