jQuery 循环——用自动停止破坏了一个循环,重新启动它,现在它停止在第二张幻灯片上,而不是遍历所有幻灯片

发布于 2024-12-29 08:25:24 字数 1279 浏览 0 评论 0原文

我有一个 jQuery 循环滑块 (.team_spotlight),有 9 张幻灯片。它被设置为自动停止。自动停止后,它应该触发一个自定义函数来销毁滑块,然后重新启动所有内容。

滑块第一次遍历所有 9 张幻灯片时,效果非常好。然而,在滑块被破坏然后重新启动后,它会停止在第二张幻灯片上,而不是循环浏览所有 9 张幻灯片。

这种奇怪设置的原因是我每次都会将一个自定义类(“翻转”)添加到我的寻呼机中。幻灯片前进。你可以想象我的寻呼机是这样的——活动页面是黄色的,之前的页面是红色的,即将到来的页面是绿色的。我还在每个页面中插入唯一的 ID,这样我就可以做一些更多的风格事情。

完成所有幻灯片后,我需要重置寻呼机,因为当我们循环回到第一张幻灯片时,我需要所有页面再次变为绿色。因此,循环的销毁和重新启动。

如果有更好的方法来实现这种颜色效果(无需破坏滑块),我洗耳恭听。否则,我需要修复为什么循环在被销毁并重新启动后“卡在”第二张幻灯片上。

我的 javascript:

function paginate(ind, el) {
    return '<a class="slidenav" id="slide' + ind + '"></a>';
}   

function shifttab() {
    $('.activeSlide').addClass('flip');
}

function resettabs() {
    $('.team_spotlight').cycle('destroy');
    tabsanim();
}

function tabsanim() {
    $('.team_spotlight').cycle({
        fx: 'fade',
        pause: 1,
        speed: 0,
        timeout: 4000,
        cleartypeNoBg: true,
        pager:  '#pagernav',
        pagerAnchorBuilder: paginate,
        pagerEvent: null,
        after: shifttab,
        autostop: 1,
        end: resettabs
    });     
}


$(document).ready(function() {
    tabsanim();
});

编辑:

销毁错误仍然存​​在,修复它会很有用。

不过,我已经能够通过操作当前页面及其同级来复制我想要的效果。我不再需要销毁并重新启动滑块。

I have a jQuery cycle slider (.team_spotlight) that has 9 slides. It is set to autostop. After autostop, it should trigger a custom function that destroys the slider, then restarts everything.

The first time the slider goes through all 9 slides, it works great. However, after the slider is destroyed, then restarts, it stops on the second slide, instead of cycling through all 9.

The reason for this weird setup is I have a custom class ("flip") being added to my pager each time a slide advances. You can envision my pager like this -- Active page is yellow, previous pages are red, upcoming pages are green. I also insert unique IDs into each page so I can do a few more style things.

Once I'm done with all the slides, I need to reset my pager because I need all the pages to be green again when we loop back around to the first slide. Hence, the destroy and restart of the cycle.

If there is a better way to achieve this color effect (without having to destroy the slider), I'm all ears. Otherwise, I need a fix as to why the cycle gets "stuck" on the second slide after being destroyed and restarted.

My javascript:

function paginate(ind, el) {
    return '<a class="slidenav" id="slide' + ind + '"></a>';
}   

function shifttab() {
    $('.activeSlide').addClass('flip');
}

function resettabs() {
    $('.team_spotlight').cycle('destroy');
    tabsanim();
}

function tabsanim() {
    $('.team_spotlight').cycle({
        fx: 'fade',
        pause: 1,
        speed: 0,
        timeout: 4000,
        cleartypeNoBg: true,
        pager:  '#pagernav',
        pagerAnchorBuilder: paginate,
        pagerEvent: null,
        after: shifttab,
        autostop: 1,
        end: resettabs
    });     
}


$(document).ready(function() {
    tabsanim();
});

EDIT:

The destroy bug still stands, and it would be useful to fix it.

However, I've been able to duplicate the effect I want by manipulating my current page and its siblings. I no longer have a need to destroy and restart the slider.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无言温柔 2025-01-05 08:25:24

尝试注释掉或删除该行:

autostop: 1,

in tabsanim()

这里的新功能

function tabsanim() {
    $('.team_spotlight').cycle({
        fx: 'fade',
        pause: 1,
        speed: 0,
        timeout: 4000,
        cleartypeNoBg: true,
        pager:  '#pagernav',
        pagerAnchorBuilder: paginate,
        pagerEvent: null,
        after: shifttab,
        end: resettabs
    });     
}

............
以下计时器没有解决问题,但上面的更改解决了问题

function resettabs() {
    $('.team_spotlight').cycle('destroy');
    setTimeout("tabsanim()",300);
    }

Try to comment out or remove the line:

autostop: 1,

in tabsanim()

Here the new function ...

function tabsanim() {
    $('.team_spotlight').cycle({
        fx: 'fade',
        pause: 1,
        speed: 0,
        timeout: 4000,
        cleartypeNoBg: true,
        pager:  '#pagernav',
        pagerAnchorBuilder: paginate,
        pagerEvent: null,
        after: shifttab,
        end: resettabs
    });     
}

.................
The following timer DID NOT solve the problem, but the above change solved it

function resettabs() {
    $('.team_spotlight').cycle('destroy');
    setTimeout("tabsanim()",300);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文