Skip to content

Instantly share code, notes, and snippets.

@simogeo
Created October 22, 2017 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simogeo/c94aa80be3194523b3a43948ce78ae4c to your computer and use it in GitHub Desktop.
Save simogeo/c94aa80be3194523b3a43948ce78ae4c to your computer and use it in GitHub Desktop.
Responsive leanModal
(function($){
$.fn.extend({
leanModal: function(options) {
var defaults = {
top: 100,
overlay: 0.5,
closeButton: null
}
var overlay = $("<div id='lean_overlay'></div>");
$("body").append(overlay);
options = $.extend(defaults, options);
return this.each(function() {
var o = options;
$(this).click(function(e) {
var modal_id = $(this).attr("href");
$("#lean_overlay").click(function() {
close_modal(modal_id);
});
$(o.closeButton).click(function() {
close_modal(modal_id);
});
var modal_height = $(modal_id).outerHeight();
var modal_width = $(modal_id).outerWidth();
$('#lean_overlay').css({ 'display' : 'block', opacity : 0 });
$('#lean_overlay').fadeTo(200,o.overlay);
$(modal_id).css({
'display' : 'block',
'position' : 'absolute',
'top':'50%',
'left': '50%',
'transform': 'translate(-50%, -50%)',
'opacity' : 0,
'z-index': 11000
});
$(modal_id).fadeTo(200,1);
e.preventDefault();
});
});
function close_modal(modal_id){
$("#lean_overlay").fadeOut(200);
$(modal_id).css({ 'display' : 'none' });
}
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment