« Previous entry | Next entry » Browse > Snippets
Skip to comments (18)
Javascript: Overlay
Posted by JDBurnZ on Apr 30 2008 @ 07:12 :: 1381 unique visits
Initially, I had been using a modified version of lightbox (left over from when I was a javascript n00b,) to create an overlay which forced the user to perform some action in that area before being able to return to the original page.That being said, the script was a cumbersome 55KB in size and wasn't even functionized how I would have liked it to be.
After finally getting up the ambition to create my own version which is from my testing, 100% compatible with both Firefox and Internet Explorer, I figured I would share my code. This code is FREE to use and distribute for any reason you wish as so long as you credit the developer (me).
CODE: JAVASCRIPT
function overlayBox(url, overlayBgOpacity, overlayBoxHeight, overlayBoxWidth, overlayBgColor, overlayBoxColor) {
if(!overlayBoxColor) {
overlayBoxColor = "#ffffff";
if(!overlayBgColor) {
overlayBgColor = "#666666";
if(!overlayBoxWidth) {
overlayBoxWidth = "500px";
if(!overlayBoxHeight) {
overlayBoxHeight = "350px";
if(!overlayBgOpacity) {
overlayBgOpacity = 7;
}
}
}
}
}
// Containing box
var overlayBox = document.createElement("div");
overlayBox.setAttribute("id" ,"overlayBox");
overlayBox.style.height = overlayBoxHeight;
overlayBox.style.width = overlayBoxWidth;
overlayBox.style.position = "absolute";
overlayBox.style.top = "0px";
overlayBox.style.left = "0px";
overlayBox.style.height = "100%";
overlayBox.style.width = "100%";
overlayBox.style.zIndex = "9999";
overlayBox.innerHTML = "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\" border=\"1\"><tr><td valign=\"middle\" align=\"center\"><div id=\"overlayContent\" style=\"height: " + overlayBoxHeight + "; width: " + overlayBoxWidth + "; background-color: " + overlayBoxColor + ";\"></div></td></tr></table>";
// Partially transparent background
var overlayBg = document.createElement("div");
overlayBg.setAttribute("id", "overlayBg");
overlayBg.setAttribute("height", "100%");
overlayBg.setAttribute("width", "100%");
overlayBg.style.position = "absolute";
overlayBg.style.top = "0px";
overlayBg.style.left = "0px";
overlayBg.style.height = "100%";
overlayBg.style.width = "100%";
overlayBg.style.backgroundColor = overlayBgColor;
if(overlayBgOpacity == "10") {
overlayBg.style.opacity = "1.0";
} else {
overlayBg.style.opacity = "." + overlayBgOpacity;
}
overlayBg.style.filter = "alpha(opacity=" + overlayBgOpacity + "0)";
overlayBox.style.zIndex = "9998";
overlayBg.innerHTML = "<table width=\"100%\" height=\"100%\"><tr><td> </td></tr></table>";
// Apply the DIVs as a child to BODY
document.getElementsByTagName("body")[0].appendChild(overlayBg);
document.getElementsByTagName("body")[0].appendChild(overlayBox);
ajaxGet("overlayContent", url);
}
function overlayBoxClose() {
document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlayBox"));
document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlayBg"));
}
if(!overlayBoxColor) {
overlayBoxColor = "#ffffff";
if(!overlayBgColor) {
overlayBgColor = "#666666";
if(!overlayBoxWidth) {
overlayBoxWidth = "500px";
if(!overlayBoxHeight) {
overlayBoxHeight = "350px";
if(!overlayBgOpacity) {
overlayBgOpacity = 7;
}
}
}
}
}
// Containing box
var overlayBox = document.createElement("div");
overlayBox.setAttribute("id" ,"overlayBox");
overlayBox.style.height = overlayBoxHeight;
overlayBox.style.width = overlayBoxWidth;
overlayBox.style.position = "absolute";
overlayBox.style.top = "0px";
overlayBox.style.left = "0px";
overlayBox.style.height = "100%";
overlayBox.style.width = "100%";
overlayBox.style.zIndex = "9999";
overlayBox.innerHTML = "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\" border=\"1\"><tr><td valign=\"middle\" align=\"center\"><div id=\"overlayContent\" style=\"height: " + overlayBoxHeight + "; width: " + overlayBoxWidth + "; background-color: " + overlayBoxColor + ";\"></div></td></tr></table>";
// Partially transparent background
var overlayBg = document.createElement("div");
overlayBg.setAttribute("id", "overlayBg");
overlayBg.setAttribute("height", "100%");
overlayBg.setAttribute("width", "100%");
overlayBg.style.position = "absolute";
overlayBg.style.top = "0px";
overlayBg.style.left = "0px";
overlayBg.style.height = "100%";
overlayBg.style.width = "100%";
overlayBg.style.backgroundColor = overlayBgColor;
if(overlayBgOpacity == "10") {
overlayBg.style.opacity = "1.0";
} else {
overlayBg.style.opacity = "." + overlayBgOpacity;
}
overlayBg.style.filter = "alpha(opacity=" + overlayBgOpacity + "0)";
overlayBox.style.zIndex = "9998";
overlayBg.innerHTML = "<table width=\"100%\" height=\"100%\"><tr><td> </td></tr></table>";
// Apply the DIVs as a child to BODY
document.getElementsByTagName("body")[0].appendChild(overlayBg);
document.getElementsByTagName("body")[0].appendChild(overlayBox);
ajaxGet("overlayContent", url);
}
function overlayBoxClose() {
document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlayBox"));
document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlayBg"));
}
Note: For this to display correctly in Internet Explorer (of course,) there is always a catch... You have to specify the height of the BODY tag to 100%. If you don't, the result is rather.. Unexpected! :)
18 comments posted so far
Add your own »
2. On Oct 30 2008 @ 13:04 karen wrote:
The latest music newsISMUSIC
TRY-NET
HeartyLadder
ARIADNE
YUUCHAN'S ROOM
FX
INGJAPAN HomePage
MEMORIZE
At Iguider's in Japan
fx
artelmedical.com
fx
Ladys Room
Netster Search Engine
cdlrdesign.com
B&G SIGNS
www.ceiecjx.com
TMPGEnc
The latest entertainments news
3. On Nov 24 2008 @ 17:11 guest wrote:
bachidaietokigu
rakuto
biyou
hutomomo
human
oohara
manepa
kyouiku
kekkon
piring
bridal
FX1000
gaitame
sikaku ohara
4. On Dec 10 2008 @ 07:05 nian wrote:
The open policy <a href="http://www.oxyfun.org" title="dofus kamas">dofus kamas</a>means that our country is open to investment, trade and technical and economic cooperation with other countries on the basis of equality and mutual benefit<a href="http://www.oxyfun.org" title="kamas dofus">kamas dofus</a>. The purpose of open policy is to acquire advanced technology, management skills to serve our socialist construction so as to promote the realization of the four modernizations.5. On Dec 10 2008 @ 07:05 nian wrote:
The open policy <a href="http://www.oxyfun.org" title="dofus kamas">dofus kamas</a>means that our country is open to investment, trade and technical and economic cooperation with other countries on the basis of equality and mutual benefit<a href="http://www.oxyfun.org" title="kamas dofus">kamas dofus</a>. The purpose of open policy is to acquire advanced technology, management skills to serve our socialist construction so as to promote the realization of the four modernizations.6. On Mar 09 2009 @ 04:21 guest wrote:
サイト制作秋葉原 メイド
ペット火葬 つくば
つくば ペット火葬
つくば ペット霊園
つくば ペット葬儀
立食パーティー用プレート
でしこ
soul source production
ベトナム シーフード
高収入 アルバイト
高収入 アルバイト
アパレル 求人
アパレル 派遣
人妻 出会い
風俗
風俗
デリヘル
アダルトゲーム
高収入求人
高収入求人
ソープランド
性感マッサージ 名古屋
M性感 名古屋
出会い
7. On Mar 09 2009 @ 09:57 guest wrote:
Weaknesses of world of warcraft gold the client-server model used by World of Warcraft have been wow power levelingexploited in order to crash the cluster of servers that make up a realm. Exploits also include characters being able to instantly change location or teleport. The situation Cheap Wow Goldbecame worse when trying to coordinate activities across a number of players cheapest wow goldor guilds on the same realm.World of Warcraft Lead Producer, stated that new realms would be introduced to relieve the burden on existing ones. Existing realms would be upgraded.Although the game wow gold follows a similar model to others in the genreand was noted for having buy cheap wow gold many familiar concepts from roleplaying games, the new approaches wow gold cheapto reduce pauses between game encounters was well liked. At various times, World of Warcraft players have experienced problems with connecting to and logging in to wow gold for salethe game. Sudden server crashes that would force realms offline also occurred.
8. On Mar 10 2009 @ 05:24 hoang wrote:
サイト制作秋葉原 メイド
ペット火葬 つくば
つくば ペット火葬
つくば ペット霊園
つくば ペット葬儀
立食パーティー用プレート
でしこ
soul source production
ベトナム シーフード
高収入 アルバイト
高収入 アルバイト
アパレル 求人
アパレル 派遣
人妻 出会い
風俗
風俗
デリヘル
アダルトゲーム
高収入求人
高収入求人
ソープランド
性感マッサージ 名古屋
M性感 名古屋
出会い
9. On Mar 16 2009 @ 13:24 guest wrote:
I call ajaxGet to do all the dirty work, and populate the contents of the DIV, overlayContent. You could instead, use overlayBox.innerHTML = "something"; instead. Alternately, you may search for my customized AJAX code, which supports both POST and GET methods.tower defense10. On Mar 20 2009 @ 13:06 cqx wrote:
You have a choicecheap wow gold I woke up early buy wow goldtoday, excited overworld of warcraft gold all I get buy wow goldto do beforedofus kamas the clock strikes kamas dofusmidnight. I have Final Fantasy XI gilresponsibilities to ffxi gilfulfill today. I lotr goldam important. Myflyff penya job is to choose buy flyff goldwhat kind of Maple Story Mesosday I am goingMaple Story meso to have. Today EverQuest 2 goldI can complain eq2 platbecause the weather Runescape goldis rainy or I Runescape moneycan be thankful Runescape Moneythat the grass Runescape Power levelingis getting watered Runescape Goldfor free. Today ffxi gilI can fell saddofus kamas that I don’t kamas dofushave more money ordofus kamas I can be glad kamas dofusthat my finances dofus kamasencourage me to kamas dofusplan my purchasesdofus kamas wisely and guide kamas dofusme away from waste I am alive.11. On Mar 20 2009 @ 13:06 cuicui wrote:
The thing thathair straighteners goes the farthestGHD toward making chi hair straightenerslife worthwhile,Thatreplica handbags costs the leastwholesale handbags and does the replica designer handbagsmost, is just replica watcha pleasant smile.swiss replica watchesThe smile thatreplica rolex watches bubbles from thepuma shoes heart that loves nike shoesits fellow men,womens clothesWill drive away ed hardy clothingthe clouds of replica handbagsgloom and coax replica watchesthe sun again.Designer clothingIt’s full of Designer replica handbagsworth and goodness,Wholesale jewelry too, with manly Replica rolex watcheskindness blent;replica handbagIt’s worth a Replica Handbagsmillion dollars, and Replica Watchesit doesn’t cost replica designer handbagsa cent. ThereCoach Handbags is no room Gucci Handbagsfor sadness when Rolex Watcheswe see a cheery smile;It always has the same good look; it’s never out of style; It nerves us on to try again when failure makes us blue.12. On Mar 20 2009 @ 13:07 xiang wrote:
A taxi driverwow gold prices has taught me wow gold hacksone million U.S.wow gold guides dollars in the cheap wow gold euhour of customer wow gold gamesatisfaction and make wow goldtrust. Motivationalwow gold shop speakers charge wow europe goldthousands of dollarswow fishing to convey thiswow gold trade kind of training wow gold makingto managers and wow gold onlineemployees. It costwow hacks me a $ 12 taxi.paladin wow I had flown gold in wowinto Dallas for very cheap wow goldthe sole purpose wow gold sellerof calling onbuy gold for wow a client. The wow gold exchangetime was the cheap gold for wowessence and my selling wow goldplan to providewow gold guide a quick turnaround wow gold pricetrip from and buy cheap wow goldback to the airport.buy guild wars gold A clean cab sell wow goldpulled up. The drivercheapest wow gold America's loss is the friend!13. On Apr 07 2009 @ 17:40 guest wrote:
wholesale replica handbagsFendi Replica handbags
Chanel Replica handbags
Replica handbags
Gucci replica handbags
Miumiu replica handbags
Hermes replica handbags
YSL replica handbags
chloe replica handbags
Jimmy Choo replica handbags
marc jacobs replica handbags
louis vuitton replica handbags
Replica Christian Louboutin Shoes
14. On May 25 2009 @ 08:09 maryzheng wrote:
We have been producing hydraulic tools, hydraulic crimping tool and other kinds of crimping tools.We can provide our customer good quality ,pvc windows machine,Wholesale PVC window hardwares, PE pipe fittings and other pvc prod\ugg boots, world wild ugg boots cheap ugg boots, ugg boot, cheap ugg boot, ugg cardy, ugg cardy for uk, cheap ugg cardy boots are popular,we sell real ugg boots, cheap ugg boots, ugg cardy, cheap ugg cardy boots,ugg boots uk at great prices to people, we are proud to offer you the high quality and low price ugg classic cardy,ugg classic cardy shop, cardy ugg boots, cheap cardy ugg boots, ugg classic cardy boots, ugg classic cardy boots online, and ugg classic tall, ugg classic tall boot, ugg boots uk, cardy ugg boots are using 100% natural sheepskin
15. On Jun 25 2009 @ 04:13 guest wrote:
DVD Audio RipperFree DVD Audio Ripper
DVD Audio Ripper for Mac
DVD to MP4 Converter
DVD to MP4 Converter for Mac
DVD to iPod Converter
free DVD to iPod Converter
DVD to iPod Converter for Mac
DVD Ripper
Diablo 2 CD Key
Diablo 2 CD Keys
Free DVD Ripper
DVD Ripper for Mac
NFL Jerseys
Scoccer Jerseys
Hockey Jerseys
MLB Jerseys
NHL Jerseys
Nike Sneakers
16. On Jul 14 2009 @ 04:01 guest wrote:
buy wow goldmy wow power leveling
buy wow gold
good wow power leveling
BUY wow gold
my wow power leveling
CHEAP rs gold
cheap wow power leveling
CHEAPEST lotro gold
MY aion gold
buy wow gold
cheap wow gold
CHEAPEST wow gold
17. On Jul 14 2009 @ 08:52 guest wrote:
AVI to DVD Converter,AVI to DVD Creator,iPhone Ringtone Maker for Mac,AVI Converter OS X,VOB Converter OS X,AVCHD Video Converter,FLV Converter,PowerPoint Converter,AVCHD Converter,Blue-Ray ripper,FLV to MOV Mac,VOB to DVD,HD Video Converter,iPod Playlist Transfer18. On Jan 05 2010 @ 14:56 uggbaileybutton wrote:
bailey button uggs-ugg boots cheap
ugg boots uk
ugg classic
1. On Apr 30 2008 @ 07:15 JDBurnZ wrote:
A working example:To close the overlay, in somepage.php use the overlayBoxClose() function:
Also note: In this example I call ajaxGet to do all the dirty work, and populate the contents of the DIV, overlayContent. You could instead, use overlayBox.innerHTML = "something"; instead.
Alternately, you may search for my customized AJAX code, which supports both POST and GET methods.