Skip to content

Instantly share code, notes, and snippets.

@westonwatson
Created October 19, 2012 04:40
Show Gist options
  • Select an option

  • Save westonwatson/3916272 to your computer and use it in GitHub Desktop.

Select an option

Save westonwatson/3916272 to your computer and use it in GitHub Desktop.
Simple LightBox jQuery Plugin
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SIMBOX EXAMPLE</title>
<style>
.black_overlay{
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
-moz-opacity: 0.5;
opacity:.50;
filter: alpha(opacity=50);
}
.white_content {
display: none;
position: absolute;
top: 25%;
left: 25%;
width: 50%;
height: 50%;
padding: 2em;
/*border: 2px solid #666;*/
background-color: white;
z-index:1002;
overflow: auto;
box-shadow: 0em 0em 3px #000 inset;
border-radius: 2px;
}
.close_btn {
position: absolute;
right: 10px;
top: 10px;
z-index:1003;
}
</style>
<link rel="stylesheet" href="http://ace-subido.github.com/css3-microsoft-metro-buttons/css/m-styles.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
/*
* Note: both buttons are expected jQuery objects (or DOM elements)
* if okBtn is used, you need to pass a jquery object bound
* to a function, otherwise, it won't do anything...
*/
jQuery(function(){ //load plugin after jQuery is done brewing.
var simBoxSettings = {
closeBtn : jQuery('<img/>').attr('src','http://i.imgur.com/J6Ki3.png').attr('border','0'), //create a jQuery object for the CloseBTN
okBtn : jQuery(), //same thing, OkBTN
title : null,
speed : 'fast',
};
jQuery.close_simbox = function(settings){
jQuery('.black_overlay').fadeOut(settings.speed, function(){ jQuery(this).remove(); });
jQuery('.white_content').fadeOut(settings.speed, function(){ jQuery(this).remove(); });
};
jQuery.simbox = function(contentHTML,settings){
jQuery.close_simbox(settings);
var settings = settings ? jQuery.extend({},simBoxSettings,settings) : simBoxSettings; //defaults if null
//append the lightbox and set content functions
jQuery('body').append(
jQuery('<div/>').addClass('white_content').html( //create contentDIV and assign css class
(settings.title ? jQuery('<h1>').html(settings.title).after('<br/>') : '' ) //set title if given
+ contentHTML).fadeIn(settings.speed).append( //set contentHTML
jQuery('<a href="#">').append( //append close-btn link
jQuery(settings.closeBtn).click(function(){ //append user object and bind close method
jQuery.close_simbox(settings);
})
).addClass('close_btn') //add css class to close-btn
)
);
//append the background overlay
jQuery('body').append(
jQuery('<div/>').addClass('black_overlay').fadeIn(settings.speed)
);
};
});
</script>
</head>
<body>
</body>
</html>
@westonwatson
Copy link
Author

just saving it here for now. Creating a repo soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment