Decrease Font Size
Increase Font Size
   BLOG

JQuery slideshow with XML

by bryian 8. October 2009 21:03

Simple Gallery with jQuery |

JQuery Simple Controls Gallery |

JQuery slideshow |

JQuery simplegallery.js |

JQuery Image Gallery with XML

Watch this Script in action/ Download

Introduction

I am using the JQuery Simple Controls Gallery from Drive DHTML (dynamic html) & JavaScript code library . One of the requirements is to read the images information from a XML file. After spending some time researching for it, I found the article Reading XML with jQuery. I have put together these two findings and include a brief explanation to it. Hope someone will find this information useful. Comments are welcome.

JQuery Slideshow

Implementation

<script type="text/javascript">
    var myArray = []; //declare and initialize array
/* 
10082009 BT
http://think2loud.com/reading-xml-with-jquery/
Read the slides info into an array from XML and assign the array variable to
the simple slide show.
*/
    $(document).ready(function() {
        $.ajax({
            type: "GET",
            url: "simplegallery_files/sites.xml", //xml file 
			dataType: "xml",
            success: function(xml) {
                var count = 0; //counter
                $(xml).find('site').each(function() {

                    var url = $(this).find('url').text(); //url 
                    var target = $(this).find('target').text(); //_blank, _new
                    var imageURL = $(this).find('imageURL').text(); //location of the image
                    var alt = $(this).find('alt').text(); //alternate text of the image

					//append to array
                    myArray[parseInt(count)] = new Array(imageURL, url, target, alt); 
					
                    count++;
                });

                var mygallery2 = new simpleGallery({
                    wrapperid: "simplegallery2", //ID of main gallery container,
                    dimensions: [728, 90], //width/height of gallery in pixels. Should reflect dimensions of the images exactly
					
                    imagearray: myArray, //assing the array var to here
                    autoplay: [true, 10000, 99], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]
                    persist: true,
                    fadeduration: 1000, //transition duration (milliseconds)
                    oninit: function() { //event that fires when gallery has initialized/ ready to run
                    },
                    onslide: function(curslide, i) { //event that fires after each slide is shown
                        //curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)
                        //i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)
                    }
                })
            }
        });

    });
</script>

Sample XML contents

<?xml version="1.0" encoding="iso-8859-1"?>
<sites>

  <site>
    <url><![CDATA[https://www.amazon.com/b?node=283155&tag=asp.net.books-20&camp=0&creative=0&linkCode=ur1&adid=1F4JYCPDSWG3V5JH9GD9&]]></url>
    <target>_new</target>
    <alt>Amazon :: Books</alt>
    <imageURL><![CDATA[https://images-na.ssl-images-amazon.com/images/G/01/associates/2006/books/34percent/us_books_728x90.gif]]></imageURL>
  </site>

  <site>
    <url><![CDATA[http://www.mochahost.com/1160-0-1-29.html]]></url>
    <target>_new</target>
    <alt>MochaHost</alt>
    <imageURL>http://www.mochasupport.com/aff/banners/112_728-4.gif</imageURL>
  </site>

</sites>

Comments

10/2/2009 12:32:20 PM #

trackback

JQuery slideshow with XML Data Source

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com

10/3/2009 11:15:55 AM #

trackback

Daily tech links for .net and related technologies - October 9-11, 2009

Daily tech links for .net and related technologies - October 9-11, 2009 Web Development Using MvcContrib

Sanjeev Agarwal

10/19/2009 7:55:14 AM #

scratch and dent

good post Thank for sharing

scratch and dent United States

1/18/2010 3:21:23 AM #

get pregnant fast

I like this post very much I like to use on my blog.

get pregnant fast United States

1/19/2010 12:58:26 AM #

Forex Trading

Thanks for the share very usefull.

Regards
-logon2future

Forex Trading United States

1/29/2010 10:33:44 AM #

Full Tilt Rakeback

I was pretty confused about using Jquery properly but this has helped alot.  Thanks, and please continue to make new tutorials.  Btw that slideshow is pretty sweet.

Full Tilt Rakeback United States

Add comment


(Will show your Gravatar icon)

  Country flag

Click to change captcha
biuquote
  • Comment
  • Preview
Loading