Created
August 13, 2014 19:27
-
-
Save anonymous/98b12edd22f3df93ed1c to your computer and use it in GitHub Desktop.
Custom simple lightbox
This file contains 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
(function($) { | |
// SIMPLE BOX | |
// make your own lightbox cuz they all suck | |
var imgSrc | |
, $simpleBox; | |
window.fitImg = function() { | |
var $img = $("#simple-box img"); | |
$($img).css("max-width", $(window).width() - 20); | |
$($img).css("max-height", $(window).height() - 40); | |
}; | |
$(".post img").click(function() { | |
$("#simple-box").remove(); // remove if one already exists | |
imgSrc = $(this).attr("src"); | |
$simpleBox = $("<div style='display:table;width:100%;height:100%;position:fixed;z-index:999999;top:0;left:0;'><div id='simple-box' style='background-color:rgba(0,0,0,0.7);display:table-cell;vertical-align:middle;text-align:center;'><img class='fade-in one' src='"+ imgSrc +"' style='box-shadow:0 0 50px rgba(0,0,0,0.5);' onload='fitImg()'></div></div>"); | |
$("body").append($simpleBox); | |
}); | |
// "close" the modal | |
$("body").on("click", "#simple-box", function() { | |
$("#simple-box").remove(); | |
}); | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment