2016-03-11 22 views
1

我想使div專注於onclick。 Draggable完美地工作,但是當我完成我的拖動選項時,div會變得焦點。我還需要刪除光標:移動光標:汽車當點擊分區。請幫我..如何避免聚焦一個div,當它是點擊並拖動..?

$(function() { 
var block = $('#text-block') 
block.find('.editable-text').resizable({ 
    containment: $('#drag-area'), 
    handles: { 
     nw: block.find('.nw'), 
     ne: block.find('.ne'), 
     sw: block.find('.sw'), 
     se: block.find('.se') 
    }, 
    minWidth: 50, minHeight: 18 
}) 
}); 

$(function() { 
$(".editable-text").draggable(); 
}); 

我的代碼在JSfiddle ...!

回答

0

添加下面一行在你的CSS下.editable-text選擇

.editable-text { 
    /*your old code*/ 
    outline:none; 
} 

fiddle

編輯: 防止文本選擇 添加noselectnoselect ,寫在你的CSS文件中的以下

.noselect { 
    -webkit-touch-callout: none; /* iOS Safari */ 
    -webkit-user-select: none; /* Chrome/Safari/Opera */ 
    -khtml-user-select: none; /* Konqueror */ 
    -moz-user-select: none;  /* Firefox */ 
    -ms-user-select: none;  /* IE/Edge */ 
    user-select: none;   

}

,也看改變光標jQuery的變化,如果你正在尋找

Fiddle3 updated

副本這個js代碼

$(function() { 
    var block = $('#text-block') 
    block.find('.editable-text').resizable({ 
    containment: $('#drag-area'), 
    handles: { 
     nw: block.find('.nw'), 
     ne: block.find('.ne'), 
     sw: block.find('.sw'), 
     se: block.find('.se') 
    }, 
    minWidth: 50, minHeight: 18 
    }) 
}); 

$(function() { 
    $(".editable-text").draggable(); 

$(".editable-text").mousedown(function(e){ 
    if(e.which == 1) { 
     $(this).css({ 
     'cursor':'move' 
     }); 
      }else{ 
     $(this).css({ 
      'cursor':'auto' 
     }); 
    } 
}); 
}); 
+0

感謝您的答覆。但當我點擊並拖動完成時,我需要不關注div。拖動後,您的代碼將焦點放入div中進行編輯。 – ArunValaven

+0

現在拖動不起作用,並且當點擊時光標也不會改變。 – ArunValaven

+0

現在檢查fiddle2更新的鏈接,我在jQuery代碼中有錯誤 – alamnaryab

相關問題