Last active
August 29, 2015 14:01
-
-
Save fmtarif/b3c80f9d5844b6a061cb to your computer and use it in GitHub Desktop.
#js lightweight modal/lightbox boilerplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<link rel="stylesheet" href="modal.css"> | |
</head> | |
<body> | |
<h1><a class="js-modal-trigger" data-target-modal="#js-modal-1" href="javascript:;">Trigger Modal 1</a></h1> | |
<h1><a class="js-modal-trigger" data-target-modal="#js-modal-2" href="javascript:;">Trigger Modal 2</a></h1> | |
<div id="js-modal-1" class="modal-1 modal"> | |
<a class="js-close ico-close" href="javascript:;">X</a> | |
<div class="modal-content"> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
</div> | |
</div> | |
<!--/modal--> | |
<div id="js-modal-2" class="modal-2 modal"> | |
<a class="js-close ico-close" href="javascript:;">X</a> | |
<div class="modal-content"> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
</div> | |
</div> | |
<!--/modal--> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
<script src="jquery.lightbox_me.min.js"></script> | |
<script src="modal-trigger.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* basics */ | |
.modal { | |
display: none; | |
position: relative; | |
} | |
.modal-1, | |
.modal-2 | |
{ | |
width: 700px; | |
background-color: #E1E1E1; | |
color: #333; | |
} | |
.ico-close { | |
font-size: 2em; | |
position: absolute; | |
right: 20px; | |
top: 5px; | |
} | |
.modal-content { | |
padding: 40px 60px;; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* http://buckwilson.me/lightboxme/ */ | |
(function(e){e.fn.lightbox_me=function(t){return this.each(function(){function u(){var t=i[0].style;if(n.destroyOnClose){i.add(r).remove()}else{i.add(r).hide()}if(n.parentLightbox){n.parentLightbox.fadeIn(200)}if(n.preventScroll){e("body").css("overflow","")}s.remove();i.undelegate(n.closeSelector,"click");i.unbind("close",u);i.unbind("repositon",l);e(window).unbind("resize",f);e(window).unbind("resize",l);e(window).unbind("scroll",l);e(window).unbind("keyup.lightbox_me");n.onClose()}function a(e){if((e.keyCode==27||e.DOM_VK_ESCAPE==27&&e.which==0)&&n.closeEsc)u()}function f(){if(e(window).height()<e(document).height()){r.css({height:e(document).height()+"px"});s.css({height:e(document).height()+"px"})}else{r.css({height:"100%"})}}function l(){var t=i[0].style;i.css({left:"50%",marginLeft:i.outerWidth()/2*-1,zIndex:n.zIndex+3});if(i.height()+80>=e(window).height()&&i.css("position")!="absolute"){var r=e(document).scrollTop()+40;i.css({position:"absolute",top:r+"px",marginTop:0})}else if(i.height()+80<e(window).height()){if(n.centered){i.css({position:"fixed",top:"50%",marginTop:i.outerHeight()/2*-1})}else{i.css({position:"fixed"}).css(n.modalCSS)}if(n.preventScroll){e("body").css("overflow","hidden")}}}var n=e.extend({},e.fn.lightbox_me.defaults,t),r=e(),i=e(this),s=e('<iframe id="foo" style="z-index: '+(n.zIndex+1)+';border: none; margin: 0; padding: 0; position: absolute; width: 100%; height: 100%; top: 0; left: 0; filter: mask();"/>');if(n.showOverlay){var o=e(".js_lb_overlay:visible");if(o.length>0){r=e('<div class="lb_overlay_clear js_lb_overlay"/>')}else{r=e('<div class="'+n.classPrefix+'_overlay js_lb_overlay"/>')}}e("body").append(i.hide()).append(r);if(n.showOverlay){f();r.css({position:"absolute",width:"100%",top:0,left:0,right:0,bottom:0,zIndex:n.zIndex+2,display:"none"});if(!r.hasClass("lb_overlay_clear")){r.css(n.overlayCSS)}}if(n.showOverlay){r.fadeIn(n.overlaySpeed,function(){l();i[n.appearEffect](n.lightboxSpeed,function(){f();l();n.onLoad()})})}else{l();i[n.appearEffect](n.lightboxSpeed,function(){n.onLoad()})}if(n.parentLightbox){n.parentLightbox.fadeOut(200)}e(window).resize(f).resize(l).scroll(l);e(window).bind("keyup.lightbox_me",a);if(n.closeClick){r.click(function(e){u();e.preventDefault})}i.delegate(n.closeSelector,"click",function(e){u();e.preventDefault()});i.bind("close",u);i.bind("reposition",l)})};e.fn.lightbox_me.defaults={appearEffect:"fadeIn",appearEase:"",overlaySpeed:250,lightboxSpeed:300,closeSelector:".close",closeClick:true,closeEsc:true,destroyOnClose:false,showOverlay:true,parentLightbox:false,preventScroll:false,onLoad:function(){},onClose:function(){},classPrefix:"lb",zIndex:999,centered:false,modalCSS:{top:"40px"},overlayCSS:{background:"black",opacity:.3}}})(jQuery) | |
/* trigger */ | |
jQuery(document).ready(function($) { | |
$(".js-modal-trigger").click(function(e) { | |
e.preventDefault(); | |
var target = $(this).attr('data-target-modal'); | |
if (!$(target).length) | |
return; | |
$(target).lightbox_me({ | |
closeSelector: ".js-close" | |
//,overlaySpeed: 150 | |
//,lightboxSpeed: 'fast' | |
//,centered: true | |
//,overlayCSS: {background: 'black', opacity: .7} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment