views:

740

answers:

3

I have a slideshow built in flash that I want to mimic in jQuery. The slide show uses the images from the slideshow as the pager numbers. The problem im having is once i apply links to the slideshow images the pagerAnchorBuilder image returns an undefined for the src of the image.

Javascript -

$(function() {
$('#slideshow').before('<ul id="nav">').cycle({
    fx:     'fade',
    timeout: 7000,
    pager:  '#nav',
    pagerAnchorBuilder: function(idx, slide) {
    return '<li><a href="#"><img src="' + slide.src + '" width="100" height="60" /></a></li>';
    }
});  
});

HTML -

<div id="slideshow" class="pics"> 
    <a href="http://google.com"&gt;&lt;img src="home_1.jpg" width="1000" height="600" /></a>
    <a href="http://google.com"&gt;&lt;img src="home_2.jpg" width="1000" height="600" /></a>
    <a href="http://google.com"&gt;&lt;img src="home_3.jpg" width="1000" height="600" /></a> 
    <a href="http://google.com"&gt;&lt;img src="home_4.jpg" width="1000" height="600" /></a> 
    <a href="http://google.com"&gt;&lt;img src="home_5.jpg" width="1000" height="600" /></a> 

</div> 

If i remove the href's from the slideshow the images in the pager show up without issues. Im not sure if this is a bug or something i need to find a fix for?

Here is the answer -

$(function() {
$('#slideshow').before('<ul id="nav">').cycle({
    fx:     'fade',
    timeout: 7000,
    pager:  '#nav',
    pagerAnchorBuilder: function(idx, slide) {
      var img = $(slide).children().eq(0).attr("src");
      return '<li><a href="#"><img src="' + img + '" width="100" height="60" /></a></li>';
    }

});

});

+1  A: 

Read this may help you!

http://stackoverflow.com/questions/1370127/jquery-cycle-pageranchorbuilder

aSeptik
A: 

Seems to be a common problem! Check out cycle with anchors and also cycle's "slideExpr"

Ben
A: 

I used JQuery .find() to help find the images, and to keep the code modular enough to use with different markup:

pagerAnchorBuilder: function(idx, slide) {
            return '<li><a href="#"><img src="' + jQuery(slide).find('img').attr('src') + '" width="120" /></a></li>'; 
        }
Sal