Skip to content

Instantly share code, notes, and snippets.

@ww24
Created September 14, 2011 22:56
Show Gist options
  • Save ww24/1218056 to your computer and use it in GitHub Desktop.
Save ww24/1218056 to your computer and use it in GitHub Desktop.
Very Simple LightBox
/*
* jquery.vslb.js
* とてもシンプルなLightBoxプラグイン
* Version : 0.1.1 rev1
* Copyright : ww24
* License : MIT License
*/
(function ($) {
var count = 0;
$.fn.vslb = function (options) {
options = options ? options : {};
var $target = $(this);
if ($target.parent().attr("class") !== "slightbox-lb") {
var zIndex = options.zIndex ? options.zIndex : 0 + count++,
$win = $(window),
$lb = $target.wrap('<div class="slightbox-lb" />').parent();
$("body").append('<div class="slightbox-bg" title="close" />')
.find(".slightbox-bg:last-child").click(function () {
count--;
$(this).remove();
$target.unwrap();
if (options.close) {
options.close();
}
}).css({
zIndex: zIndex++,
opacity: 0
}).animate({opacity: 0.8});
$lb.css({
width: $lb.width(),
height: $lb.height(),
left: $win.width() / 2 - $lb.outerWidth() / 2 + $win.scrollLeft(),
top: $win.height() / 2 - $lb.outerHeight() / 2 + $win.scrollTop(),
zIndex: zIndex,
display: "none"
}).fadeIn("normal", function () {
if (options.open) {
options.open();
}
});
}
return this;
};
})(jQuery);
.slightbox-bg {
width : 100%;
height : 100%;
position : fixed;
top : 0;
left : 0;
background : #555;
cursor : pointer;
}
.slightbox-lb {
position : absolute;
padding : 5px;
border : 3px #3080d0 solid;
background : #fff;
}
.slightbox-lb > * {
display : block !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment