gpt4 book ai didi

javascript - 使用 Modulus 为 jquery 循环自定义寻呼机返回

转载 作者:行者123 更新时间:2023-11-30 13:26:22 25 4
gpt4 key购买 nike

尝试让这个自定义寻呼机为 jQuery Cycle 工作。

我希望 pagerAnchorBuilder 每 5 张图像返回一个 list 项,这样稍后我可以将寻呼机变成它自己的循环。

代码如下:

  pagerAnchorBuilder: function(idx,slide){
var $slideCount = $('#ul-homecycle > li').length;
if ((idx==0) || (idx%5 === 0)){
return '<li><a href="javascript:setSlide('+ idx +')" class="transhover"><img src="../images/home/thumb_carousel' + idx + '.jpg" width="183" height="72" /></a></li>';
}
else{
return '<a href="javascript:setSlide('+ idx +')" class="transhover"><img src="../images/home/thumb_carousel' + idx + '.jpg" width="183" height="72" /></a>';

}
}

所以最后我希望 Cycle 返回这个:

<ul>
<li>
<a href="javascript:void(0);">derp</a>
<a href="javascript:void(0);">derp</a>
<a href="javascript:void(0);">derp</a>
<a href="javascript:void(0);">derp</a>
<a href="javascript:void(0);">derp</a>
</li>
<li>
<a href="javascript:void(0);">derp</a>
<a href="javascript:void(0);">derp</a>
<a href="javascript:void(0);">derp</a>
<a href="javascript:void(0);">derp</a>
<a href="javascript:void(0);">derp</a>
</li>
</ul>

请忽略 setSlide(#) 和 JS 返回的 HTML 字符串中的类值,我已经控制住了。即使搜索了 2 小时,我也无法弄清楚。

提前致谢!

最佳答案

我终于明白了。这是修改后的代码,为了您的方便而注释:

function cycles(){
//Activate main slide with proper pager/carousel container.
$('#ul-homecycle').after('<div id="homecycle-carousel-container"><a href="javascript:void(0);" id="btn-homecycle-prev" class="transhover"></a><a href="javascript:void(0);" id="btn-homecycle-next" class="transhover"></a><ul id="homecycle-carousel">').cycle({
timeout: 7000,
speed: 500,
sync: true,
fx: 'fade',
fit: 0,
startingSlide: 2,
activePagerClass:'active',
slideResize: 0,
pager: '#homecycle-carousel',
pagerAnchorBuilder: function(idx,slide){
return '<a href="javascript:setSlide('+ idx +')" class="transhover"><img src="../images/home/thumb_carousel' + idx + '.jpg" width="183" height="72" /></a>';
},
// Build pager that automagically hightlights updated pager thumb and also continue to next pager slide if the next thumb isn't visible
updateActivePagerLink: function(pager, activeIndex) {
$(pager).find('a').not(':eq('+activeIndex+')').removeClass('active').children('img').fadeTo(200,.5)
$(pager).find('a:eq('+activeIndex+')').addClass('active').children('img').fadeTo(200, 1);

//If next slide in carousel is hidden then go to next carousel slide
if ($(pager).find('a:eq('+activeIndex+')').parent('li').css('display') == "none"){
$('#homecycle-carousel').cycle('next');
}
}
});
//Before building the carousel wrap an Li around every 5 thumbs
$('#homecycle-carousel > a').each(function(i) {
var a = $('#homecycle-carousel > a');
for( var i = 0; i < a.length; i+=5 ) {
a.slice(i, i+5).wrapAll('<li></li>');
}
});
//Now that we have Lis wrapped around every 5 thumbs, initiate new cycle
$('#homecycle-carousel').cycle({
easing: 'easeOutSine',
prev: '#btn-homecycle-prev',
next: '#btn-homecycle-next',
slideExpr: 'li',
activePagerClass:'active',
timeout:0,
speed: 500,
fx: 'scrollHorz'
});
//Artifically activate new thumb
$('#homecycle-carousel li a').click(function(){
if(!$(this).hasClass('active')){
$('#homecycle-carousel li a').not(this).removeClass('active').children('img').fadeTo(200,.5);
$(this).addClass('active').children('img').fadeTo(200,1);
}
});

}

关于javascript - 使用 Modulus 为 jquery 循环自定义寻呼机返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8304334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com