我正在寻找类似的东西,并找到了使用mousedown和mouseup事件的可能解决方案。这不是最优雅的解决方案,但它是唯一一个在Chrome和Firefox上一直为我工作的解决方案。
我加了一些JavaScript到您的提琴: Fiddle
;
(function($) {
// DOM Ready
$(function() {
$('input').on('mousedown', function(e) {
e.stopPropagation();
$('div.parent').attr('draggable', false);
});
$(window).on('mouseup', function(e) {
$('div.parent').attr('draggable', true);
});
/**
* Added the dragstart event handler cause
* firefox wouldn't show the effects otherwise
**/
$('div.parent').on({
'dragstart': function(e) {
e.stopPropagation();
var dt = e.originalEvent.dataTransfer;
if (dt) {
dt.effectAllowed = 'move';
dt.setData('text/html', '');
}
}
});
});
}(jQuery));
有许多可拖动库周围 – charlietfl
这是这样一个基本特征,我觉得应该可以用普通的HTML和JavaScript的最少。 – zjabbari
当然...如果你想处理这样的跨浏览器问题,这些问题已经被标准化并且在现有的库 – charlietfl