-
Notifications
You must be signed in to change notification settings - Fork 1.1k
implement option draggable #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
heres what I've been using.., thanks to hompimpaalaihumgambreng jquery $('.modal').drags({handle: '.modal-header'}) // Simple JQuery Draggable Plugin
// https://plus.google.com/108949996304093815163/about
// http://hompimpaalaihumgambreng.blogspot.com/2012/06/draggable-without-jquery-ui.html#.UJ4VxmckTg0
// Usage: $(selector).drags();
// Options:
// handle => your dragging handle.
// If not defined, then the whole body of the
// selected element will be draggable
// cursor => define your draggable element cursor type
(function($) {
$.fn.drags = function(opt) {
opt = $.extend({handle:"",cursor:"move"}, opt);
if(opt.handle === "") {
var $el = this;
} else {
var $el = this.find(opt.handle);
}
return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
if(opt.handle === "") {
var $drag = $(this).addClass('draggable');
} else {
var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
}
var z_idx = $drag.css('z-index'),
drg_h = $drag.outerHeight(),
drg_w = $drag.outerWidth(),
pos_y = $drag.offset().top + drg_h - e.pageY,
pos_x = $drag.offset().left + drg_w - e.pageX;
// $drag.css('z-index', 1000).parents().on("mousemove", function(e) {
$drag.parents().on("mousemove", function(e) {
$('.draggable').offset({
top:e.pageY + pos_y - drg_h,
left:e.pageX + pos_x - drg_w
}).on("mouseup", function() {
$(this).removeClass('draggable').css('z-index', z_idx);
});
});
e.preventDefault(); // disable selection
}).on("mouseup", function() {
if(opt.handle === "") {
$(this).removeClass('draggable');
} else {
$(this).removeClass('active-handle').parent().removeClass('draggable');
}
});
}
})(jQuery); |
Hey, thanks for the issue but I don't think I will be implementing this directly in Bootstrap Modal at this time. I think it's a bit out of scope for this plugin and as @Yohn suggests, there are a few libraries dedicated to this functionality already. |
extend option ? $().modal({ drags: true }) |
The issue I have with this is I would need to either:
Both involve to some degree choosing a library, I would much rather the developer have that choice. It will also muddy up the code to directly include a library, especially when the feature is really only desirable in a desktop enviroment. This is why I believe it to be out of scope for this plugin. As @Yohn pointed out in his example, it is fairly trivial to add the support yourself. |
I am using your drag function, however, is it possible to reset to its original position upon relaunch? Currently, if I close the modal and open it again, it stays at the previously dragged position.. So if i dragged one of my modal off screen a bit, the next one is stayed off screen. Thanks |
what you could do is when the modal is shown, get the offset so you have the original placement - I havent tested this as I havent played with it in a few months, but in theory it should work. |
Thanks for the code. It's working for me. |
I believe you could do something like |
Reset to original position : |
$(".modal").draggable({
handle: ".modal-header",cursor: "move"
})
thank
The text was updated successfully, but these errors were encountered: