-
Notifications
You must be signed in to change notification settings - Fork 19
/
jquery.tiny-draggable.js
25 lines (24 loc) · 1.04 KB
/
jquery.tiny-draggable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
jQuery tinyDraggable v1.0.2
Copyright (c) 2014 Simon Steinberger / Pixabay
GitHub: https://github.com/Pixabay/jQuery-tinyDraggable
More info: https://pixabay.com/blog/posts/p-52/
License: http://www.opensource.org/licenses/mit-license.php
*/
(function($){
$.fn.tinyDraggable = function(options){
var settings = $.extend({ handle: 0, exclude: 0 }, options);
return this.each(function(){
var dx, dy, el = $(this), handle = settings.handle ? $(settings.handle, el) : el;
handle.on({
mousedown: function(e){
if (settings.exclude && ~$.inArray(e.target, $(settings.exclude, el))) return;
e.preventDefault();
var os = el.offset(); dx = e.pageX-os.left, dy = e.pageY-os.top;
$(document).on('mousemove.drag', function(e){ el.offset({top: e.pageY-dy, left: e.pageX-dx}); });
},
mouseup: function(e){ $(document).off('mousemove.drag'); }
});
});
}
}(jQuery));