Solved

How do i create the modal box with the lightbox effect

Posted on 2008-10-10
9
869 Views
Last Modified: 2013-11-19
I trying  to create the pop up with the light box effect ... but i am new in javascript i don't not understand the  hard core javascript code can u guys help me in this ...

I just want to open my div with the effect of background fade just like light box

pl z Excuse  me for my English

thanks in advance
0
Comment
Question by:Manish09
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:lucki_luke
ID: 22685385
Hey,

please have a look at this code.
It uses a lot of CSS to accomplish the effect.
The div "light" is where your content for the "popup" goes.

Source: http://www.emanueleferonato.com/2007/08/22/create-a-lightbox-effect-only-with-css-no-javascript-needed/
<head>

    <title>LIGHTBOX 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.8;

        opacity:.80;

        filter: alpha(opacity=80);

    }

    .white_content {

        display: none;

        position: absolute;

        top: 25%;

        left: 25%;

        width: 50%;

        height: 50%;

        padding: 16px;

        border: 16px solid orange;

        background-color: white;

        z-index:1002;

        overflow: auto;

    }

</style>

</head>

<body>

    <p>This is the main content. To display a lightbox click <a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">here</a></p>

    <div id="light" class="white_content">This is the lightbox content. <a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">Close</a></div>

    <div id="fade" class="black_overlay"></div>

</body>

Open in new window

0
 
LVL 1

Author Comment

by:Manish09
ID: 22685415
Hi lucki_luke

Please have look ....ur code is cool...but not working in IE 6 ...

Thanks For Reply plz check in IE 6 need it badly working this form last three days plz help  
<head>

    <title>LIGHTBOX 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.8;

        opacity:.80;

        filter: alpha(opacity=80);

    }

    .white_content {

        display: none;

        position: absolute;

        top: 25%;

        left: 25%;

        width: 50%;

        height: 50%;

        padding: 16px;

        border: 16px solid orange;

        background-color: white;

        z-index:1002;

        overflow: auto;

    }

</style>

</head>

<body>

    <p>This is the main content. To display a lightbox click <a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">here</a></p>

    <p>&nbsp;</p>

   

        <select name="select" id="select">

          <option>select box </option>

        </select>

     

    <p>&nbsp;</p>

    <div id="light" class="white_content">This is the lightbox content. <a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">Close</a></div>

    <div id="fade" class="black_overlay"></div>

</body>

Open in new window

0
 
LVL 1

Author Comment

by:Manish09
ID: 22685423
lucki_luke  one more thing IE 6   ( width: 100%;   height: 100%; )  does not support the percentage values
0
 
LVL 9

Expert Comment

by:lucki_luke
ID: 22685550
Okay,
then we will have to use a larger library, like ThickBox ( http://jquery.com/demo/thickbox/ ).
Use the code below and download
http://jquery.com/demo/thickbox/thickbox-code/thickbox.js
http://jquery.com/demo/thickbox/thickbox-code/thickbox.css
http://jquery.com/demo/thickbox/images/loadingAnimation.gif
http://jquery.com/src/jquery-latest.js

Put these files in a subfolder called thickbox and rename jquery-latest.js to jquery.js.
You should read the section "How to implement ThickBox" since you will have to make a slight modification to the files.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>

<script type="text/javascript" src="thickbox/jquery.js"></script>

<script type="text/javascript" src="thickbox/thickbox.js"></script>

<link rel="stylesheet" href="thickbox/thickbox.css" type="text/css" media="screen" />

</head>

<body>

<a href="#TB_inline?height=300&width=300&inlineId=inner_content" class="thickbox">Show</a>

<div id="inner_content" style="display:none;">

    <div><h3>It is a hidden div!</h3>

    Place your content here.

    </div>

</div>

</body>

</html>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Manish09
ID: 22685666
Hi lucki_luke

yes u r right i l am also planning to do the same thick box but i am not good in scripting so ..not able do the same

i am attaching the modal box which i need to open.. above the form without any close button

i am facing one more problem...   i tried  with the light box but in that i am not able to do the adjustment for the forms select box comes up above the light box effect in ie 6

plz excuse me for my English  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>LIGHTBOX EXAMPLE</title>

<style type="text/css">

.lightbox {

	width:343px;

	background-color:#fff;

	padding:20px 0px 0px 0px;

	border-top:1px solid #C9C7C9;

	border-right:1px solid #C9C7C9;

	border-bottom:3px solid #C9C7C9;

	border-left:1px solid #C9C7C9;

}

.lightbox img {

	margin:0px 15px 0px 10px;

}

.lightbox p {

	margin-bottom:15px;

}

.lightbox_bot {

	background-color:#F4ECF4;

	padding:0px 5px 0px 5px;

	width:97%

}

.fl{ float:left}

.fr{ float:right}

</style>

</head>

<body>

<div id="box2" class="lightbox" style="display:;"> <img src="images/alert_ico.jpg" class="fl " />

  <div class="fr" style="width:84%">

    <p>You have made changes to your Personal Information.</p>

    <p>Click on the Save & Continue button to save & proceed to the next step.</p>

  </div>

  <div class="lightbox_bot fl">

    <button class="action_btn_g fr" id="cancel_link"><span>Cancel</span></button>

    <button class="action_btn_p fr" ><span>Save & Continue</span></button>

    <div class="clear"></div>

  </div>

</div>

</body>

</html>

Open in new window

0
 
LVL 9

Expert Comment

by:lucki_luke
ID: 22685710
Hi Manish09.

please have a look at the attached code. Your box now comes without any close button and the content is the one you supplied.

However, I'm not quite understanding your other other problem. Could you please try to explain it a bit more clearly and/or attach screenshots or so.

Thanks
Lukas
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>

<script type="text/javascript" src="thickbox/jquery.js"></script>

<script type="text/javascript" src="thickbox/thickbox.js"></script>

<link rel="stylesheet" href="thickbox/thickbox.css" type="text/css" media="screen" />

<style type="text/css">

.lightbox {

        width:343px;

        background-color:#fff;

        padding:20px 0px 0px 0px;

        border-top:1px solid #C9C7C9;

        border-right:1px solid #C9C7C9;

        border-bottom:3px solid #C9C7C9;

        border-left:1px solid #C9C7C9;

}

.lightbox img {

        margin:0px 15px 0px 10px;

}

.lightbox p {

        margin-bottom:15px;

}

.lightbox_bot {

        background-color:#F4ECF4;

        padding:0px 5px 0px 5px;

        width:97%

}

.fl{ float:left}

.fr{ float:right}

</style>

</head>

<body>

<a href="#TB_inline?height=120&width=300&inlineId=box2&modal=true" class="thickbox">Show</a>

<div id="box2" class="lightbox" style="display:none;"> <img src="images/alert_ico.jpg" class="fl " />

  <div class="fr" style="width:84%">

    <p>You have made changes to your Personal Information.</p>

    <p>Click on the Save & Continue button to save & proceed to the next step.</p>

  </div>

  <div class="lightbox_bot fl">

    <button class="action_btn_g fr" id="cancel_link"><span>Cancel</span></button>

    <button class="action_btn_p fr" ><span>Save & Continue</span></button>

    <div class="clear"></div>

  </div>

</div>

</body>

</html>

Open in new window

0
 
LVL 1

Author Comment

by:Manish09
ID: 22686371
Hi lucki_luke

Hey thanks buddy...now its working  can u  just give me little more help

please explain the changes wat u did in the code for the next time ..... it will help me thanks and

one more thing i need to ask how can i implement my css in the thickbox code

thanks
0
 
LVL 9

Accepted Solution

by:
lucki_luke earned 500 total points
ID: 22686650
Hi Manish09,

the basis for my code is of course a simple HTML document. Then following the instructions at http://jquery.com/demo/thickbox/ I downloaded all necessary files and put the <script> statements and the CSS link and definitions from your code into the header (and adjusted the path of course; edited the .js as explained there etc).

After that, I had a look at the example "Inline Content". So I created an anchor element and took your div with the "popup" and set the href property of the a element to "#TB_inline?height=120&width=300&inlineId=box2" as described there (box2 is the ID of your popup). Since you don't want a close button, I added "&modal=true" to the string which removes the close button. I fixed the property of display in your div to style="display:none;" so that it doesn't appear if the button is not pressed.

I hope this clarifies the steps.

If you want to change the CSS or merge your CSS with the Thickbox CSS you can either just modify the file Thickbox.css or copy the content to a <style> element into the header and make the adjustments there (of course you should remove the link to the stylesheet then).

Lukas
0
 
LVL 1

Author Closing Comment

by:Manish09
ID: 31504934
Thank you so much Lukas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Bootstrap 3 and Angular 2 12 55
How can I do a Select All on this page? 8 36
rearranging, beautifying pure CSS read more script 5 42
CSS Position not returning 2 48
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now