javascript - 在 JQuery 插件中拖动元素时禁用悬停、文本选择等

标签 javascript jquery

我有一个轮播基于:

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/

相关文章:

javascript - 围绕 Canvas 圆绘制条形音箱

javascript - iframe 移动响应

javascript - promise 加入变革 promise 一切

javascript - jQuery就绪回调的调用顺序

javascript - 用按钮替换文本

javascript - 通过javascript添加meta标签可以在源码中看到

jquery - CSS 菜单和 JQuery

javascript - 在 Angular 2 中获取一个 json 文件

jquery - 排除 div 中的选择器

javascript - 如何使用 ajax 将 ObjectID 发送到后端 (Node.JS)