473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to add jquery fade effect on ajax html banner rotator?

Tj Jurado
Hi guys,
I am new to this and need a little help.
I have an html block to be rotated and placed in an array via php as well as printed as an xml format then. Without refreshing the page, the banner will randomly rotate using ajax technique.
I wanted to add a jquery fade effect or a code in which every time the block of html code rotates, or a transition effect. The code are shown below for html, php & javascript:

the html page:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  3.     <head>
  4.         <title>AJAX banner demo</title>
  5.         <style type="text/css">
  6.             #ajax-banner {
  7.                 background: #ceeffd;
  8.                 padding:10px;
  9.                 border: 1px solid black;
  10.                 width: 760px; height: 460px; position: relative; margin: 0 auto 15px; 
  11.             }
  12.         </style>
  13.  
  14.     </head>
  15.  
  16.     <body>
  17.         <div id="ajax-banner"></div>
  18. <script type="text/javascript" src="ajax-banner.js"></script>
  19. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
  20. <!-- include Cycle plugin --> 
  21. <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> 
  22.     </body>
  23. </html>
  24.  
The php:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // an array of banners
  3. $banners = array (
  4.     '<img src="images/12-volt-engel-products/engel-12-volt-acdc-fridge-freezer-43-quart-mt45-sm.jpg" alt="Engel 12-Volt Fridge Freezer" style="float: right; margin: 0 0 2px 10px;">
  5.                                 <h3>Medium Engel 12 Volt AC/DC Fridge-Freezer 34 Quart MT35F-U1</h3>
  6.                                 <h4>Features:</h4>
  7.                                 <ul>
  8.                                 <li>Input rating DC12V - 2.5A</li>
  9.                                 <li>AC 110V - 0.7A</li>
  10.                                 <li>Fuse 10A external fuse</li>
  11.                                 <li>Max Noise 38 dB</li>
  12.                                 <li>Shipping Weight 59 lbs.</li>
  13.                                 <li>Warranty 2 years</li>
  14.                                 </ul>
  15.                                 <br>
  16.                                 <h3 style="text-align: right;color:#ff0000;margin-right:30px">Now $763.99</h3>
  17.                                 <br>
  18.                                 <form action="http://www.romancart.com/cart.asp" method="post">
  19.                                 <p style="text-align: right;"><input type="hidden" name="itemcode" value="00620402024">
  20.                                 <input type="hidden" name="storeid" value="00000">
  21.                                 Quantity: <input name="quantity" size="1" type="text" value="1">
  22.                                 <input name="Submit" type="submit" value="Add to cart" style="background-color:#3366FF;font-weight:bold;color:#fff"></p>
  23.                                 </form>',
  24.     '<img src="images/gps-truck-rout-products/rand-mcnally-intelliRoute-trucker-gps-tnd700-sm.jpg" alt="TND700" style="float: right; margin: 0 0 2px 10px;">
  25.                                 <h3>Rand McNally TND700 IntelliRoute 7&quot; Trucker GPS TND700</h3>
  26.                                 <h4>Features:</h4>
  27.                                 <ul>
  28.                                     <li>Full U.S. and Canada maps</li>
  29.                                     <li>Trucker Business Tools</li>
  30.                                     <li>Access to updates and upgrades via the <a title="TND Dock" href="http://trucking.randmcnally.com/ctonline/products/intelliroute_tnd/tnd_dock.jsp">TND Dock</a></li>
  31.                                     <li>Searchable truck stop information from the Trucker's Friend National Truck Stop Directory</li>
  32.                                 </ul>
  33.                                 <h3 style="text-align: right;color:#ff0000;">Before: <span style="text-decoration:line-through;">$499.00</span><br>now $449.00</h3>
  34.                                 <br>
  35.                                 <form action="http://www.romancart.com/cart.asp" method="post">
  36.                                 <p style="text-align: right;"><input type="hidden" name="itemcode" value="00020502083">
  37.                                 <input type="hidden" name="storeid" value="00000">
  38.                                 Quantity: <input name="quantity" size="1" type="text" value="1">
  39.                                 <input name="Submit" type="submit" value="Add to cart" style="background-color:#3366FF;font-weight:bold;color:#fff"></p>
  40.                                 </form>',
  41.     '<img src="images/12-volt-lcd-tv-dvd-widescreen-products/skyworth-15.6in-tv-dvd-slc-1569a-3-small.jpg" alt="12 Volt TV" style="float: right; margin: 0 0 2px 10px;">
  42.                                 <h3>13&quot; 12v LCD TV/DVD Combo Skyworth SLC-1369A-3</h3>
  43.                                 <h4>Features:</h4>
  44.                                 <ul>
  45.                                     <li>TV adopts 13&quot; LCD display screen</li>
  46.                                     <li>HDTV Compatible( 480p,720p, 1080i, 1080p)</li>
  47.                                     <li>Support American TV Standard 8VSB/Free 64/256QAM,NTSC System, ATSC System</li>
  48.                                 </ul>
  49.                                 <h3 style="text-align: right;color:#ff0000;margin-right:50px;">Now $212.90</h3>
  50.                                 <br>
  51.                                 <form action="http://www.romancart.com/cart.asp" method="post">
  52.                                 <p style="text-align: right;"><input type="hidden" name="itemcode" value="00020202082">
  53.                                 <input type="hidden" name="storeid" value="00000">
  54.                                 Quantity: <input name="quantity" size="1" type="text" value="1">
  55.                                 <input name="Submit" type="submit" value="Add to cart" style="background-color:#3366FF;font-weight:bold;color:#fff"></p>
  56.                                 </form>',
  57. );
  58. // pick a random one
  59. $html = $banners[array_rand($banners)];
  60.  
  61. // send XML headers
  62. header('Content-type: text/xml');
  63. echo '<?xml version="1.0" ?>';
  64.  
  65. // print the XML response
  66. ?>
  67. <banner>
  68.     <content><?php echo htmlentities($html); ?></content>
  69.     <reload>4000</reload>
  70. </banner>
  71.  
The javascript:
Expand|Select|Wrap|Line Numbers
  1. function makeHttpRequest(url, callback_function, return_xml)
  2. {
  3.    var http_request = false;
  4.  
  5.    if (window.XMLHttpRequest) { // Mozilla, Safari,...
  6.        http_request = new XMLHttpRequest();
  7.        if (http_request.overrideMimeType) {
  8.            http_request.overrideMimeType('text/xml');
  9.        }
  10.  
  11.    } else if (window.ActiveXObject) { // IE
  12.        try {
  13.            http_request = new ActiveXObject("Msxml2.XMLHTTP");
  14.        } catch (e) {
  15.            try {
  16.                http_request = new ActiveXObject("Microsoft.XMLHTTP");
  17.            } catch (e) {}
  18.        }
  19.    }
  20.  
  21.    if (!http_request) {
  22.        alert('Unfortunatelly you browser doesn\'t support this feature.');
  23.        return false;
  24.    }
  25.    http_request.onreadystatechange = function() {
  26.        if (http_request.readyState == 4) {
  27.            if (http_request.status == 200) {
  28.                if (return_xml) {
  29.                    eval(callback_function + '(http_request.responseXML)');
  30.                } else {
  31.                    eval(callback_function + '(http_request.responseText)');
  32.                }
  33.            } else {
  34.                alert('There was a problem with the request.(Code: ' + http_request.status + ')');
  35.            }
  36.        }
  37.    }
  38.    http_request.open('GET', url, true);
  39.    http_request.send(null);
  40. }
  41.  
  42. function loadBanner(xml)
  43. {
  44.     var html_content = xml.getElementsByTagName('content').item(0).firstChild.nodeValue;
  45.     var reload_after = xml.getElementsByTagName('reload').item(0).firstChild.nodeValue;
  46.     document.getElementById('ajax-banner').innerHTML = html_content;
  47.  
  48.     try {
  49.         clearTimeout(to);
  50.     } catch (e) {}
  51.  
  52.     to = setTimeout("nextAd()", parseInt(reload_after));
  53.  
  54.  
  55. }
  56.  
  57. function nextAd()
  58. {
  59.     var now = new Date();
  60.     var url = 'ajax-banner.php?ts=' + now.getTime();
  61.     makeHttpRequest(url, 'loadBanner', true);
  62. }
  63.  
  64. window.onload = nextAd;
  65.  
Thanks in advance.

-Tj
Sep 29 '10 #1

✓ answered by acoder

You need to use it where the change is made (in the loadBanner function)
document.getElementById('ajax-banner').innerHTML = html_content;

4 5820
acoder
16,027 Expert Mod 8TB
Use fadeIn and the corresponding fadeOut.
Sep 29 '10 #2
Thank you for the response.

I tried it and placing it on the html, but it did not work out. The fade In effect did not function.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. $("#ajax-banner").load(function () {
  3.   $("#ajax-banner").fadeIn('fast', function() {
  4.     });
  5. });
  6. </script>
  7.  
Any ideas on how to integrate it with my script?
Oct 1 '10 #3
acoder
16,027 Expert Mod 8TB
You need to use it where the change is made (in the loadBanner function)
document.getElementById('ajax-banner').innerHTML = html_content;
Oct 1 '10 #4
thanks a acoder lot it's working now.
Oct 4 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Susanna | last post by:
Hi all, I'm using the following slideshow script that I found on the web to display changing images with a crossfade effect. Eventually I will be adding many more images to the slideshow. The...
0
by: Sandy.Pittendrigh | last post by:
Are there any open source ajax html editors? I want to incorporate as simple (very simple) ajax based html editor into a webapp I'm making. I spent an hour or so downloading code and saw...
2
by: kwenterprise | last post by:
Hello All, I am normally great at figuring out ways around iframe issues that frustrate us all. I am using javasript to try and break an iframe that I have a banner rotator embedded in but it...
1
by: Valentin L | last post by:
I'm new to AJAX .. In my IIS5 web apps I'm using the old VBScript in .asp pages. I've tested an AJAX banner rotator and is OK. Now I'm looking "the" library that will spare me to "re-invent...
21
by: javelin | last post by:
I created a feature in a page where a DIV displays child records of the current record. From this same page, I can submit the insertion of a new child record. However, the while the previous child...
2
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, I made a usercontrol and want to give fade effects to it. Now problem is that i m using alpha command as i use in my cool form. Nothing is happninig. How can i give fade effect to a...
1
by: nicky77 | last post by:
Hi, apologies in advance is this may be a nonsensical ramble, but I'm hoping someone can give me some advice on how to solve the following problem: I'm developing a site where the main content is...
2
by: Excel 009 | last post by:
Hi All, I have the appended code which I used for a banner rotator. It works great except that there 1. there is a border which I do not want and 2. on top of the banner there is a black bar...
4
by: pt36 | last post by:
Hi I have a small script function photo(a){ var photo = a ; document.getElementById(photoID).innerHTML = photo; } and on the body
2
by: ilija | last post by:
Hello! As I am not much familiar with javascript (I know the basics of basics), I cannot find any script that would satisfy my needs. What I want is something like this:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.