Question

layer popup with background "dimming"

Asked by: eNarc

Hi!

I wish to have a popup with background dimming - like on this page:
http://www.sitepoint.com/article/style-web-forms-css
[ on that page, to see what i mean, click the link:          1166_image1 (click to view image)    or the image associated with it ]

i would like to see the shortest and smoothest/best method possible ( code please )

Thank you

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-02-02 at 09:02:58ID23132087
Tags

css, javascript

Topics

JavaScript

,

Cascading Style Sheets (CSS)

,

Dynamic HTML (DHTML)

Participating Experts
3
Points
500
Comments
14

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Popup Menu
    I want to create a popup menu on my page similar to the ones used by Microsoft and similar companies. Can anyone help with ideas, source etc.
  2. Popup menus
    Using Javascript, how does one create a POPUP menu. Let's say I have an HTML page. On the page is an image. I want to have a popup cascading menu appear when the user hovers their mouse cursor overtop of the image. By "cacscading menu", I refer to a single popup...
  3. Struts PopUp
    Hi , I am working in struts , I have a parent window which has a popup. when i click on Add button the PopUp window should open and it has some id and lables need to be populated. when i click on 'select' button in popup window it has to close and those values should tranfe...
  4. CSS Style popup display
    Hi, I am using the style below to display a popup when a user clicks on a link. This works perfect if the link is in the top of the screen. When the user scrolls down in the page and they click some other link with the same behavior the popup displays, but ... as you guessed...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: RoonaanPosted on 2008-02-02 at 09:06:30ID: 20805000

The scripts are commonly known as "lightbox" scripts. There are different implementations, standalone or based on libraries as scriptacolous, prototype or other rich internet frameworks.
Are you already using javascript libraries, or do you prefer a "standalone" lightbox script?

Kind regards

-r-

 

by: KokoglenPosted on 2008-02-02 at 09:08:36ID: 20805008

Using a library like jQuery makes this very easy.
http://www.malsup.com/jquery/block/#page

Once you include jQuery and the plugin, the  code would be:
$.blockUI();

Pretty short.  Plus you can do all kinds of other fancy things.  Check the demos.

 

by: b0lsc0ttPosted on 2008-02-02 at 09:28:14ID: 20805087

eNarc,

A simple example of this is in the page below.  It does not need any other frameworks, etc.  If you want to get fancier then lightbox and jQuery, etc are what you should look at.

Let me know if you have any questions or need more information.

b0lsc0tt

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html>
<head>
<link href="../style.css" rel="stylesheet" type="text/css" />
<title>The page</title>
<style type="text/css">
div {
	margin: 10px auto;
}
#links {
	color: red;
}
</style>
<script type="text/javascript">
function doForm() {
	document.getElementById('formDiv').style.zIndex = "100";
	document.getElementById('formDiv').style.display = "";
	document.getElementById('body').style.backgroundColor = "#303030";
	document.getElementById('button1').style.visibility = "hidden";
}
function clearForm(frm) {
	frm.title1.value = '';
	frm.protocol.options[0].selected = true;
	frm.link1.value = '';
	frm.desc1.value = '';
}
function quitForm(frm) {
	document.getElementById('formDiv').style.zIndex = "-1";
	document.getElementById('formDiv').style.display = "none";
	document.getElementById('body').style.backgroundColor = "white";
	document.getElementById('button1').style.visibility = "visible";
	clearForm(frm);
}
function buildForm(frm) {
	if (frm.title1.value != '' && frm.link1.value != '' && frm.desc1.value != '') {
		var str = "title=" + frm.title1.value;
		str += "&proto=" + frm.protocol.value;
		str += "&link=" + frm.link1.value;
		str += "&desc=" + frm.desc1.value;
		return str;
//		alert(str); // for testing
//		return false;
	} else return false;
}
function sendForm(obj) {
	var xmlHttp = null;
	var cont = document.getElementById('links');
	var frmInfo = buildForm(obj);
	if (!frmInfo) {
		alert("No form info");
		return false;
	}
	xmlHttp = GetXmlHttpObject(stateChanged);
	xmlHttp.open("POST", "form_popup_ajax.php", false);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
	xmlHttp.send(frmInfo);
	cont.innerHTML += xmlHttp.responseText;
	quitForm(obj);
}
function GetXmlHttpObject(handler) {
	var objXmlHttp=null;
	try	{  // Firefox, Opera 8.0+, Safari
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onreadystatechange=handler
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler
	}
	catch (e) {  // Internet Explorer
		try {
			objXmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			objXmlHttp.onreadystatechange=handler
		}
		catch (e) {
			objXmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			objXmlHttp.onreadystatechange=handler
		}
	}
	return objXmlHttp;
}
function stateChanged() {
	try {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
			return xmlHttp.responseText;
		}
	}
	catch (e) {
	}
}
</script>
</head> 
<body id="body" style="margin: 25px 115px;">
<h3>My page</h3>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div> 
<div id="links"></div>
<br /><br />
<div style="width: 25%; margin: 0 auto;">
<button id="button1" onclick="doForm();">Show Form</button>
</div>
<div id="formDiv" style="width: 60%; margin: 0 auto; padding: 10px; background-color: #ccff99; text-align: center; z-index: -1; position: absolute; top: 50px; left: 150px; border: solid 1px gray; font-weight: bold; display: none;">
<h3>AJAX Javascript Popup Form</h3>
<form name="form1" action="" method="post">
Title: <input type="text" name="title1" size="65" /><br /><br />
Protocol: 
<select name="protocol">
<option value="http://">http://</option>
<option value="https://">https://</option>
<option value="ftp://">ftp://</option>
</select>
Link: <input type="text" name="link1" size="45" /><br /><br />
Description: <input type="text" name="desc1" size="55" /><br /><br /><br />
<input type="button" name="submit" value="Submit" onclick="sendForm(this.form);" />&nbsp;&nbsp;&nbsp;
<input type="button" name="reset" value="Quit" onclick="quitForm(this.form);" />
</form>
<br /><br />
</div>
</body>
</html>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:

Select allOpen in new window

 

by: eNarcPosted on 2008-02-02 at 10:46:20ID: 20805382

thank you for replying guys

ya Sage, I'm looking for the simplest and smoothest standalone version ( i dont like, or need bulked up libraries ).
Is there any shorter code than what you posted - seems to me that there's alot of redundant code in there?

 

by: KokoglenPosted on 2008-02-02 at 10:59:30ID: 20805429

The reason the libraries exist is to smooth  over lots of cross-browser problems.  Doing a fade like this sometimes acts funny in different browsers.
A smaller version of the effect: http://docs.jquery.com/Plugins/dimScreen#Code

You can look at the code and see what it's doing.  Gzipped, this code + jquery = 15k.  Not that bulky.

But I understand if you want to go solo.

 

by: b0lsc0ttPosted on 2008-02-02 at 11:10:35ID: 20805473

That page was part of an "app" so there was some extra stuff.  I have removed it and the script is now just for showing and clearing the "popup."

Let me know if you have a question or need more info.

bol

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link href="../style.css" rel="stylesheet" type="text/css" />
<title>The page</title>
<style type="text/css">
div {
	margin: 10px auto;
}
#links {
	color: red;
}
</style>
<script type="text/javascript">
function doForm() {
	document.getElementById('formDiv').style.zIndex = "100";
	document.getElementById('formDiv').style.display = "";
	document.getElementById('body').style.backgroundColor = "#303030";
	document.getElementById('button1').style.visibility = "hidden";
}
function clearForm(frm) {
	frm.title1.value = '';
	frm.protocol.options[0].selected = true;
	frm.link1.value = '';
	frm.desc1.value = '';
}
function quitForm(frm) {
	document.getElementById('formDiv').style.zIndex = "-1";
	document.getElementById('formDiv').style.display = "none";
	document.getElementById('body').style.backgroundColor = "white";
	document.getElementById('button1').style.visibility = "visible";
	clearForm(frm);
}
</script>
</head>
 
<body id="body" style="margin: 25px 115px;">
<h3>My page</h3>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
 
<div id="links"></div>
<br /><br />
<div style="width: 25%; margin: 0 auto;">
<button id="button1" onclick="doForm();">Show Form</button>
</div>
<div id="formDiv" style="width: 60%; margin: 0 auto; padding: 10px; background-color: #ccff99; text-align: center; z-index: -1; position: absolute; top: 50px; left: 150px; border: solid 1px gray; font-weight: bold; display: none;">
<h3>AJAX Javascript Popup Form</h3>
<form name="form1" action="" method="post">
Title: <input type="text" name="title1" size="65" /><br /><br />
Protocol: 
<select name="protocol">
<option value="http://">http://</option>
<option value="https://">https://</option>
<option value="ftp://">ftp://</option>
</select>
Link: <input type="text" name="link1" size="45" /><br /><br />
Description: <input type="text" name="desc1" size="55" /><br /><br /><br />
<input type="button" name="reset" value="Quit" onclick="quitForm(this.form);" />
</form>
<br /><br />
</div>
</body>
</html>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:

Select allOpen in new window

 

by: b0lsc0ttPosted on 2008-02-02 at 11:15:56ID: 20805492

eNarc,

The code I have provided and that simple example is well tested in current browsers (definitely IE6 & 7 and Firefox on PC) if I remember right.  It is basic though and if you want effects like fade and to easily change the look, etc then you may want to consider those other good suggestions (by the other experts).  Especially if you want a "plug and play" type solution.  This type of effect looks nice but since it mixes script and complicated style (CSS) it can be difficult to get the right mix.  I hope the example I provide is close to what you want because then you should be able to pretty much use that code with minor changes for content.

bol

 

by: eNarcPosted on 2008-02-02 at 11:30:56ID: 20805532

Thank you Sage, it's what I'm looking for,  the only problem is, it changes just the background color so all images and everything else on the page shows up with full transparency and in their original color. How can we fix that?

 

by: b0lsc0ttPosted on 2008-02-02 at 13:45:24ID: 20806059

The reason for that is the popup form doesn't fill the page.  The script just changes the background.  If you want to cover everything then the div needs to fill the page.

In my code this can be simply done by making the changes below to the div.  The height part is the most difficult.  If you want to "clean it up" then you can use script to calculate the browser height but that script is complex.  You need different steps for different browsers.  If you want to cover a known amount of area then just use the top, left, width, and height to do it.

Let me know if you have a question.

bol

<div id="formDiv" style="width: 100%; height: 100%; margin: 0 auto; padding: 10px; background-color: #ccff99; text-align: center; z-index: -1; position: absolute; top: 0px; left: 0px; border: solid 1px gray; font-weight: bold; display: none;">

                                              
1:

Select allOpen in new window

 

by: eNarcPosted on 2008-02-02 at 16:38:35ID: 20806722

Thank you Sage,

there are still some problems with it - for instance my flash buttons show through unaffected.
also, i now get both horizontal and vertical scrollers whenever i open the box

 

by: b0lsc0ttPosted on 2008-02-02 at 18:15:45ID: 20807088

Those types of specific can be adjusted like I described in my last comment with the exception of the Flash items.  Those can be harder to hide although I have seen scripts or solutions that supposedly do it.  This seems to becoming a new issue though, maybe even a couple of new questions.  If your page has Flash and other complex elements/parts then the solution will be much more complex.  I don't mind helping on these parts in other questions but if you want a one-step type solution then you might try some of the premade ones.  Make sure you check to see if Flash willl be handled though since that is a real unique thing.

Let me know how this helps or if you have a question.

bol

 

by: eNarcPosted on 2008-02-03 at 07:20:20ID: 20808879

thank you all :]

 

by: b0lsc0ttPosted on 2008-02-04 at 08:54:53ID: 20815997

Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...