So I am appending a div to the body and this div will popup on click of on image a
tag actually. To achieve the body overlay effect, I am using fancybox. However I am able to append the div to body, but this div doesn't load as a fancybox. Can someone help here:
My code is here:
http://jsfiddle.net/refhat/xap9F/60/
Further am I missing something in the fancybox, I am also not seeing the close cross on top right corner of fancybox in chrome and clicking anywhere on fancybox just closes the fancybox, which should not be the case.
Here is some code you could use to create an overlay:
overlay = function () {
var o, c;
this.create = function (html) {
o = $('<div />');
c = $('<div />');
h = $('<div>' + html + '</div>').appendTo(c);
var o_css = {
'position': 'absolute',
'top': '0',
'left': '0',
'width': '100%',
'height': '100%',
'background': '#000', // Background of the overlay (opacity is set later)
'z-index': '10000',
'overflow': 'hidden'
};
var c_css = {
'position': 'absolute',
'top': '50%',
'left': '50%',
'width': '300px', // Width of content box
'height': '200px', // Height of the content box
'margin-left': '-150px', // Half of content width (used to center the box)
'margin-top': '-100px', // Half of content height (used to center the box)
'background': '#fff', // Background of the content
'color': '#000', // Text color
'z-index': '10001'
};
var h_css = { 'padding': '10px' }; // If you want paddning
o.css(o_css);
c.css(c_css);
h.css(h_css);
o.fadeTo(0, 0).appendTo('body').fadeTo(500, 0.5); //0.5 is opacity, change from 0.1-1.0
c.fadeTo(0, 0).appendTo('body').fadeTo(500, 1.0); //1.0 is opacity, change from 0.1-1.0
}
this.remove = function () {
o.remove();
c.remove();
}
}
And you call it like this:
$(document).ready(function () {
o = new overlay();
o.create('HTML you want to fill the container with, example and image or/and text or maybe a link you later bind o.remove() to'); //This creates the overlay
o.remove(); // .. and this removes the overlay
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With