Advertisement
Covarr

Image rotator

Oct 22nd, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.04 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <title>jquery cars xml</title>
  6.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  7.     <style>
  8.     #carbox-outer{display:none;width:400px;height:280px;background-image:url('outer-bg.png');background-color:#000;color:#fff;margin:0;padding:0;position:fixed;}
  9.     .carbox-inner-text{position:absolute;top:235px;right:10px;margin:0;padding:0;font-family:Helvetica,Arial,Sans-Serif;font-size:20pt;text-align:right;}
  10.     div[id*=carbox-inner-]{display:none;width:400px;height:280px;background-position:57px 0;background-repeat:no-repeat;}
  11.     #overlay{position:absolute;z-index:500;bottom:0px;left:5px;}
  12.     </style>
  13. </head>
  14. <body>
  15.     <script>
  16.     var carCurrent = 1;
  17.     var carCount = 0;
  18.     $(document).ready(function () {
  19.         $.ajax({
  20.             type: "GET",
  21.             url: "cars.xml",
  22.             dataType: "xml",
  23.             success: xmlCarsParser,
  24.             error: xmlCarsError
  25.         });
  26.     });
  27.     function xmlCarsParser(xml)
  28.     {
  29.         carCount = $(xml).find("car").size();
  30.         $(xml).find("car").each(function()
  31.         {
  32.             $("#carbox-outer").append('<div id="carbox-inner-' + carCurrent + '"><div class="carbox-inner-text">' + $(this).find("Name").text() + ': ' + $(this).find("Price").text() + '</div></div>');
  33.             $("#carbox-inner-" + carCurrent).css("background-image",'url(' + $(this).find("Photo").text() +')' );
  34.             carCurrent++;
  35.         });
  36.         $("#carbox-outer").fadeIn(0);
  37.         $("#carbox-inner-1").fadeIn(500).delay(4000).fadeOut(500);
  38.         carCurrent = 2;
  39.         slideLooper();
  40.     };
  41.     function xmlCarsError()
  42.     {
  43.         alert("could not GET");
  44.     }
  45.     function slideLooper()
  46.     {
  47.         setTimeout(function () {    //  call a 3s setTimeout when the loop is called
  48.             if (carCurrent>carCount){
  49.                 carCurrent = 1;
  50.             };
  51.             $("#carbox-inner-" + carCurrent).fadeIn(500).delay(4000).fadeOut(500);
  52.             carCurrent++;         //  increment the counter
  53.             slideLooper();             //  ..  again which will trigger another
  54.         }, 5000)
  55.     }
  56.     </script>
  57.    
  58.     <div id="carbox-outer"><div id="overlay"><img src="logo-overlay.png" /></div></div>
  59.  
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement