Create a dynamic content animated footer ad for your site in just 9 jQuery lines

Have you ever seen those ads sliding up from the bottom of your page when you are visiting a website? We are going to create a simple one in just 9 jQuery lines.

Moreover, with this script you will need to add just one line to your site to display the ad.

Just to make it easier to understand, I am showing you for free the principles some “companies” sell at more than $40. According to such sites, ads like the one we are about to make should increase your conversions, have more readers sign up to your newsletter, and make you live in harmony. All in one-

Unfortunately, I am only showing you how to create such ad in a bunch of jQuery lines.

This is what we are going to make: Watch the example.

Ready for the recipe? Here we go:

A web page

Obviously, you need a webpage. Any webpage will fit, as long as you include

<div id="triqui_ad"></div>

just before the </body> tag.

jQuery

Then it’s time to add the power of jQuery to the page: insert this script between <head> and </head>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$.ajaxSetup({cache:false});
	$('#triqui_ad').wrap('<div id="triqui_container"></div>');
	$('#triqui_ad').load('ajax.php',function(){
		$('#triqui_ad').css('display','block');
		$('#triqui_container').hide().slideDown('slow');
		$('#triqui_ad').append(' &bull; <a id="triqui_ad_close">Close</a> ');
		$('#triqui_ad_close').click(function(){ 
   			$('#triqui_container').slideUp('slow'); 
  		}); 
	}); 
});
</script>

Line 1: loading the latest jQuery version. I am loading it directly from Google to get the latest stable version with no stress for my server.

Line 3: Function to be executed when the document DOM is fully loaded.

Line 4: Disabling the cache when using Ajax calls. That’s why when you reload the page in the example, you always get the current timestamp

Line 5: I had to add this line because I wanted the final user to type in as less code as possible, so at the moment you just have to add

<div id="triqui_ad"></div>

while the “real” code should be

<div id = "triqui_container"><div id="triqui_ad"></div></div>

Using wrap you will (guess what?) wrap an HTML structure around the selected element.

Line 6: This is the most important line. I am loading the result of the Ajax call made on the ajax.php file. This means I am printing inside the div everything ajax.php will echo. In my case, it will print the current date since this is the code:

1
2
3
4
5
<?php
 
echo "Hello, I am a dynamic content created on ".date('l jS \of F Y h:i:s A');
 
?>

As you can imagine, load loads data from the server and place the returned HTML into the matched element. The only issue is it caches the result, that’s why I disabled it at line 4

Line 7: Here I am showing the content of the div containing the ad. When you’ll look at the css, you’ll find there was a display:none to keep it hidden until the script is ready to work.

Line 8: Time to slide in the ad

Line 9: Appending a link to close the ad

Line 10: Triggering the link used to close the ad

Line 11: Sliding away the ad when the user clicks on the link

CSS

And finally it’s time to stylize the ad.

#triqui_container {
	width: 100%;
	position: fixed;
	bottom: 0;
}
 
#triqui_ad{
	background-color:#e5e5e5;
	border-top:1px solid black;
	height: 100px;
	text-align:center;
	display:none;
}
 
#triqui_ad_close {
	cursor: pointer;
	text-decoration: underline;
}

You can custom the stylesheet as you want as long as you set display:none to the ad and position:fixed and bottom:0 to the container.

Have fun… would you like more options?

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (9 votes, average: 4.44 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.

12 Responses

  1. Me says:

    Wow, and I was just wondering how to do something like that yesterday, awesome :)

  2. niraj says:

    where do i PM you !

  3. tiggsy says:

    Fantastic! I knew it couldn’t be that hard…

    One thing. Is it possible to delay the scrollup for, say, 10 seconds?

  4. [...] Some days ago I showed you how to create a dynamic content animated footer ad for your site in just 9 jQuery lines. [...]

  5. [...] Create a dynamic content animated footer ad for your site in just … [...]

  6. Erik says:

    BUENO!!! Love it.. Many thanks.

  7. Matt says:

    SO COOL! Is there functionality in there to set a delay? Like instead of popping up immediately, how would you make it load after about 3 seconds?

  8. Luigi says:

    Your example doesn’t work on IE6 ?

  9. How would I code it so that it only shows once per visit per user? thanks!

  10. Brollo says:

    Thanks. Had been looking for this script for ages. Works perfectly.
    One Question, how can I replace the php echo with a image which with a hyperlink to a another webpage.

Leave a Reply

flash games company