scratch/content/html/en/blog/2010-06-19-jQuery-popup-the-easy-way.md
Yann Esposito (Yogsototh) 626e18ed8e new blog entry (code popup)
2010-06-19 01:27:41 +02:00

1.7 KiB

isHidden menupriority kind created_at title author_name author_uri tags
false 1 article 2010-06-19T00:44:50+02:00 jQuery popup the easy way Yann Esposito yannesposito.com
jQuery
javascript
popup
blog
web

Some source code on this blog can be downloaded. Most of time, the code is larger than the div bloc. This is why I use a method to show this code in a large jQuery popup.

You can try clicking the following code ; remark that the content is cutted a bit after z-index:

// --- code popup --- function openPopup() { $(this).clone(false).appendTo($("#_code")); $("#_code").show(); }

function closePopup() { $("#_code").html(""); $("#_code").hide(); }

function initCode() { $(".code").click(openPopup); $(".code").css({cursor: "pointer"}); $('body').append('

'); $('#_code').css( { 'text-align': "justify", position: "fixed", left:0, top:0, width: "100%", height: "100%", "background-color": "rgba(0, 0, 0, 0.8)", 'z-index':2000, 'padding':'3px'} ); $('#_code').hide(); $('#_code').click(closePopup); } // --- end of code popup section ---

This code is the one I use to obtain this result.

What does it do?

At the loading of the page, I create a div as wide as the window. This div is a bit transparent. Then I hide it. I also take care to its z-index value to be sure it is behind all elements.

Then when we click on a div of class code, I copy the content into this new wide div, and I show it. Really simple but really efficient. No need to use a jQuery plugin.