Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>jquery cars xml</title>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
- <style>
- #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;}
- .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;}
- div[id*=carbox-inner-]{display:none;width:400px;height:280px;background-position:57px 0;background-repeat:no-repeat;}
- #overlay{position:absolute;z-index:500;bottom:0px;left:5px;}
- </style>
- </head>
- <body>
- <script>
- var carCurrent = 1;
- var carCount = 0;
- $(document).ready(function () {
- $.ajax({
- type: "GET",
- url: "cars.xml",
- dataType: "xml",
- success: xmlCarsParser,
- error: xmlCarsError
- });
- });
- function xmlCarsParser(xml)
- {
- carCount = $(xml).find("car").size();
- $(xml).find("car").each(function()
- {
- $("#carbox-outer").append('<div id="carbox-inner-' + carCurrent + '"><div class="carbox-inner-text">' + $(this).find("Name").text() + ': ' + $(this).find("Price").text() + '</div></div>');
- $("#carbox-inner-" + carCurrent).css("background-image",'url(' + $(this).find("Photo").text() +')' );
- carCurrent++;
- });
- $("#carbox-outer").fadeIn(0);
- $("#carbox-inner-1").fadeIn(500).delay(4000).fadeOut(500);
- carCurrent = 2;
- slideLooper();
- };
- function xmlCarsError()
- {
- alert("could not GET");
- }
- function slideLooper()
- {
- setTimeout(function () { // call a 3s setTimeout when the loop is called
- if (carCurrent>carCount){
- carCurrent = 1;
- };
- $("#carbox-inner-" + carCurrent).fadeIn(500).delay(4000).fadeOut(500);
- carCurrent++; // increment the counter
- slideLooper(); // .. again which will trigger another
- }, 5000)
- }
- </script>
- <div id="carbox-outer"><div id="overlay"><img src="logo-overlay.png" /></div></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement