开发者

Jquery Cycle Plugin Question

开发者 https://www.devze.com 2022-12-16 16:20 出处:网络
I have successfully installed the Cycle plugin for Jquery and have my banners cycling the way I want them. My question is around building the anchors. I am trying to build something similar to http://

I have successfully installed the Cycle plugin for Jquery and have my banners cycling the way I want them. My question is around building the anchors. I am trying to build something similar to http://www.bazaarvoice.com.

Seems like the anchors are being generated from the javascript but I could be wrong. Here is my html and javascript.

HTML

<div id="slideshow">
        <ul class="pag开发者_如何学编程er">
            <!-- will be populated with thumbs by JS -->
        </ul>
        <!-- each div is considered as a slide show -->
        <div><img src="/images/banner1.png" />You can place text here too !</div>
        <div><img src="/images/banner2.png" />and here</div>
        <div><img src="/images/banner3.png" />and even here</div>
    </div><!-- close #slideshow -->
<div id="tabs"></div>

Javascript

$("#slideshow").cycle({ 
    fx:           'fade',  // name of transition effect (or comma separated names, ex: fade,scrollUp,shuffle) 
    timeout:       5000,   // milliseconds between slide transitions (0 to disable auto advance) 
    speed:         400,    // speed of the transition (any valid fx speed value) 
    pager:         "#tabs",// selector for element to use as pager container 
    pagerClick:    null,  // callback fn for pager clicks:  function(zeroBasedSlideIndex, slideElement) 
    pagerEvent:   'hover',// name of event which drives the pager navigation 
    pagerAnchorBuilder: function(i, slide){// callback fn for building anchor links:  function(index, DOMelement) 
        return '<li class="thumb" id="thumb-1"><img src="' + slide.src + '" height="30" width="40" /></a></li>';
    },
    before: function(){ // deselect all slides
        $(".thumb").removeClass('selected');
    },
    after: function(foo, bar, opts){ // select current slide
        $("#thumb-"+opts.currSlide).addClass('selected');
    }, 
    fit:           1,     // force slides to fit container 
    pause:         1,     // true to enable "pause on hover" 
    pauseOnPagerHover: 1, // stop slideshow when pagers are being hovered
    autostop:      0,     // true to end slideshow after X transitions (where X == slide count) 
    autostopCount: 0,     // number of transitions (optionally used with autostop to define X)  
    slideExpr:     "div", // all content of div#slider is a slide. but not the pager
    fastOnEvent:   100,   // force fast transitions when triggered manually (via pager or prev/next); value == time in ms 
});

Seems like it would be in the pagerAnchorBuilder but not sure.


looks like you are missing the beginning anchor tag

pagerAnchorBuilder: function(i, slide){// callback fn for building anchor links:  function(index, DOMelement) 
    return '<li class="thumb" id="thumb-1"><img src="' + slide.src + '" height="30" width="40" /></a></li>';
},

right between the <li> and the <img> it should be. seems you have the end tage there already though. the correct way should look something like this:

pagerAnchorBuilder: function(i, slide){// callback fn for building anchor links:  function(index, DOMelement) 
    return '<li class="thumb" id="thumb-1"><a href="path-to-link"><img src="' + slide.src + '" height="30" width="40" /></a></li>';
},

if you want to change the link based on the ID of the slide, you may want something like this:

pagerAnchorBuilder: function(i, slide){// callback fn for building anchor links:  function(index, DOMelement) 
    switch(slide.attr("id")){
        case "one": return '<li class="thumb" id="thumb-1"><a href="path-to-first-link"><img src="' + slide.src + '" height="30" width="40" /></a></li>';
        case "two": return '<li class="thumb" id="thumb-1"><a href="path-to-second-link"><img src="' + slide.src + '" height="30" width="40" /></a></li>';
        case "three": return '<li class="thumb" id="thumb-1"><a href="path-to-third-link"><img src="' + slide.src + '" height="30" width="40" /></a></li>';
    }


},
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号