2011-09-07 37 views
5

Tôi đã một băng chuyền dựa tắt của:Disable di chuột, lựa chọn văn bản, vv khi kéo một phần tử trong JQuery cắm

http://nooshu.com/explore/jquery-iphone-animation/

Khi bạn đang trong quá trình lấy và kéo, bạn apt để chọn văn bản. Nếu tôi có liên kết trong các bảng, tôi nhận được thông báo di chuột, v.v ...

Tôi muốn tắt tất cả những điều đó, vì vậy khi bạn đang trong quá trình kéo, phần còn lại của tương tác sẽ bị tắt.

Ý tưởng?

Trả lời

6

Tạo một lớp kiểu như thế này:

.unselectable { 
    -moz-user-select: none; 
    -khtml-user-select: none; 
    -webkit-user-select: none; 
    user-select: none; 
    -ms-user-select : none 
} 

Sau đó thay đổi Javascript hơi gán lớp này trên mousedown. Vì vậy, từ tập lệnh không thay đổi gì, nó sẽ trông như thế này.

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

Đối vô hiệu dao động bạn cần phải unbind sự kiện trên mousedown như thế này:

$(this).unbind('mouseenter mouseleave'); 

Sau đó rebind chúng một lần nữa trên mouseup như trên.

+0

Điều đó đã làm nó, cảm ơn! – Wesley

2
document.onmousemove = function(ev) 
{ 
    ev.preventDefault(); 
    /* 
    move it 
    */ 
} 
+0

Điều này làm việc cho tôi, cảm ơn bạn! –

0

tôi sẽ hoàn thành câu trả lời Icchanobot với một dòng hơn:

-ms-user-select : none 

Để làm cho nó làm việc với Internet Explorer 11/-

Các vấn đề liên quan