Solved

How do i create the modal box with the lightbox effect

Posted on 2008-10-10
9
867 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 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

22 Experts available now in Live!

Get 1:1 Help Now