jQuery Cycle Plugin - Dictate locaton of thumbnails

落爺英雄遲暮 提交于 2019-12-20 04:30:25

问题


What I would like to do is dictate where my thumbnails are instead of using the main images as the thumbnail.

I'm pretty sure this can be done, I just need a little push in the right direction.

Here is my Code:

<script type="text/javascript">

$('#imageContainer').before('').cycle({ fx: 'fade', speed: 2000, timeout: 8000, pager: '#nav',

// callback fn that creates a thumbnail to use as pager anchor 
pagerAnchorBuilder: function(i, slide) { 
    return '<li><a href="#"><img src="' + slide.src + '" width="121" height="67" /></a></li>'; 
} 

});

And here is the HTML:

<div id="container">
<div id="imageContainer">
    <img src="http://www.ifcj.org/ifcj-08/images/elements/slideshow/1.jpg"  rel="http://www.ifcj.org/ifcj-08/images/elements/slideshow/1t.jpg" width="378" height="210" />
    <img src="http://www.ifcj.org/ifcj-08/images/elements/slideshow/2.jpg" rel="http://www.ifcj.org/ifcj-08/images/elements/slideshow/2t.jpg" width="378" height="210" />
    <img src="http://www.ifcj.org/ifcj-08/images/elements/slideshow/3.jpg" rel="http://www.ifcj.org/ifcj-08/images/elements/slideshow/3t.jpg" width="378" height="210" />
</div>
<div id="nav"></div>

Any help would do.

thank You


回答1:


If you're talking about a scenario like the one described here http://malsup.com/jquery/cycle/pager2.html, you should be able to do something like the following:

pagerAnchorBuilder: function(id, slide) { 
    var thumb_prefix = "t_";
    return '<li><a href="#"><img src="' + thumb_prefix + slide.src + '" width="50" height="50" /></a></li>';
}

This is the simplest example, of course you can do something different depending on your naming convention and particular application, for example inserting a t at the end before the extension:

pagerAnchorBuilder: function(id, slide) { 

    // Split off the filename with no extension (period + 3 letter extension)
    var new_src = slide.src.substring(0,slide.src.length-4);

    // Add the "t"
    new_src += "t";

    // Add the period and the 3 letter extension back on
    new_src += slide.src.substring(slide.src.length-4,slide.src.length);

    // Set this as the source for our image
    return '<li><a href="#"><img src="' + new_src + '" width="50" height="50" /></a></li>';
}


来源:https://stackoverflow.com/questions/1948903/jquery-cycle-plugin-dictate-locaton-of-thumbnails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!