Using Fancybox for a PopUp
22 Jan
I know, I know, a pop up is evil… and I agree. So let’s come up with a simple unobtrusive way of showing a pop up, but without actually making one. The answer… Fancybox.
If you don’t know fancybox is a jquery highlight box that allows you to display images, ajax, video, html, flash..etc.
Recently I had a client who’s site is a bit dated; wanting to put a flyer on the home page and have it pop up on load. Well, Fancybox is a perfect way to do this without using ancient ideas.
Here’s How:
1. Download the latest version of jquery (1.3.2 @ the time of this writing)
2. Download Fancybox.
3. Add this to the head of your html page:
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="js/jquery.easing.1.3.js"></script> <script type="text/javascript" src="js/jquery.fancybox-1.2.6.js"></script>
I use easing as well.. this makes the transition a bit smoother and bit cooler!
4. In your HTML, you’ll need to create a div that is set to display none… in that div, you will want to create an a href tag like this:
<div style="display: none;">
<a class="fancybox" href="mypath/myimage.jpg?phpMyAdmin=a95c4b835d3ft271e87f8"></a>
</div>5. Now, you’ll need to call the document ready class to make this world go round’. Do that by add this under the last JS call in step 3:
<script type="text/javascript"> $(document).ready(function() { $("a.fancybox").fancybox({ 'overlayOpacity' : 0.8, 'overlayColor' : 'black', 'overlayShow' : true }) }); </script>
You’ll notice, I added a few extra parameters, if you check here, you’ll see more on all the options you have.
6. Ok, last but not least, we need to make this load every time the page loads.. so to do so, we just add the onload function to the body tag. Like this:
<body onload='$("a.fancybox").trigger("click");'>So that’s it! You now have a cool pop up that’s clean, and smooth, and you’ll never have to worry about it not showing up because a user has “pop-up’s” disabled.
L
Popularity: 58%