Skip to content

Instantly share code, notes, and snippets.

@victorbstan
Forked from anonymous/simblebox.js
Last active August 29, 2015 14:05
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 victorbstan/70d44f5595de6fb9bed5 to your computer and use it in GitHub Desktop.
Save victorbstan/70d44f5595de6fb9bed5 to your computer and use it in GitHub Desktop.
(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