Comments (9)
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);
from bootstrap-modal.
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.
from bootstrap-modal.
extend option ?
$().modal({ drags: true })
from bootstrap-modal.
The issue I have with this is I would need to either:
- Include a library into Bootstrap-Modal
- Test if a library exists in Bootstrap-Modal
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.
from bootstrap-modal.
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
from bootstrap-modal.
what you could do is when the modal is shown, get the offset so you have the original placement - var offset = $('.modal').offset();
, and then when its hidden reset the offset positions to the original placement.. $('.modal').offset({top: offset.top, left: offset.left})
I havent tested this as I havent played with it in a few months, but in theory it should work.
from bootstrap-modal.
Thanks for the code. It's working for me.
The issue I have with this is, is it possible to reset to its original position upon relaunch?
from bootstrap-modal.
I believe you could do something like $('.modal').modal('layout')
to reposition the modal to the center of the screen.
from bootstrap-modal.
Reset to original position :
$('body').on('hidden.bs.modal', function() { $('.modal').css({'top': '', left:''}); });
from bootstrap-modal.
Related Issues (20)
- is there any compatibility issues with select2.js? HOT 1
- Construct ajax query (ie. ajax Contact form)
- can i use this without bootstrap HOT 1
- angular 1.2.* ng-include used inside ui-bootstrap - modal opening page scrolls to top
- Show Modal Without overlay.
- Modal opens with a delay compared to standard BS3 modal
- Use modal with form validation
- body class="modal-open" style="padding-right: 15px" HOT 1
- Modal don't scroll when closing top modal
- The bootstrap dependency is different between github repo and bower repo.
- make collapsable?
- event.relatedTarget()
- How to relocate modal inside into a div
- Publish as NPM package
- Incompatible with Boostrap 4? HOT 4
- when using this with bootbox.js ,the bootbox dialog style was confused HOT 9
- Stackable: Close modal when clicked outside
- Will you upgrade to Bootstrap 4? HOT 1
- event listener for complete loading
- Replaced # with javascript:; in this statement and it worked.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bootstrap-modal.