关于jQuery的可拖动(在jQuery的UI一个巨大的图书馆)jQuery的鼠标按下回调函数(如回调的回调)
我发现这个替代小片段用谷歌搜索:
https://gist.github.com/Arty2/11199162
万一链接死亡这里是代码:
(function($) {
if (!jQuery().draggable) {
$.fn.draggable = function() {
this
.css('cursor', 'move')
.on('mousedown touchstart', function(e) {
var $dragged = $(this);
var x = $dragged.offset().left - e.pageX,
y = $dragged.offset().top - e.pageY,
z = $dragged.css('z-index');
if (!$.fn.draggable.stack) {
$.fn.draggable.stack = 999;
}
stack = $.fn.draggable.stack;
$(window)
.on('mousemove.draggable touchmove.draggable', function(e) {
$dragged
.css({'z-index': stack, 'transform': 'scale(1.1)', 'transition': 'transform .3s', 'bottom': 'auto', 'right': 'auto'})
.offset({
left: x + e.pageX,
top: y + e.pageY
})
.find('a').one('click.draggable', function(e) {
e.preventDefault();
});
e.preventDefault();
})
.one('mouseup touchend touchcancel', function() {
$(this).off('mousemove.draggable touchmove.draggable click.draggable');
$dragged.css({'z-index': stack, 'transform': 'scale(1)'})
$.fn.draggable.stack++;
});
e.preventDefault();
});
return this;
};
}
})(jQuery);
它看起来像它缺少jquery-ui的熟悉事件:start
,move
,stop
。我正在想办法将其添加到代码中。我想;对每个月底的回调
'mousedown touchstart' //this.start()
'mousemove.draggable touchmove.draggable' //this.drag()
'mouseup touchend touchcancel' //this.stop()
喜欢的东西
this.start=function(){/*do whatever*/};
this.drag=function(){/*do whatever*/};
this.stop=function(){/*do whatever*/};
但是,我怎么会去传入通过回调的事件?
.on('mousedown touchstart', function(e, callback) { //that would not work!
我只是不知道怎样才能做一个参考this.start(),因为它不缝对我来说,这些事件可以建立一个正常的回调函数。 我的想法是; mousedown
的事件函数是一个自己的回调函数,所以似乎我不得不通过第二次回调,这将导致draggable.start
如何将动态回调传递给事件函数?
我发现这个库http://draggabilly.desandro.com/其中有事件开始拖动停止。
但我还是真的想知道如果我可以通过一个事件..动态传递一个回调