gpt4 book ai didi

javascript - 通过for循环迭代函数x次

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:03:34 28 4
gpt4 key购买 nike

$('.ip_button').click(function(){
var buttonValue, slideTimes;
buttonValue = $(this).html();
slideTimes = parseInt(buttonValue) - 1;
for (var i = 0 ; i < slideTimes; i++) {
slider.gallery_next();
}
});

您好,我正在尝试使用确定按钮 -1 值的函数在 slider 上滑动多个图像并多次运行幻灯片。不幸的是,无论按钮中有什么值,函数都只会执行一次。当前按钮中的值是:

<button class="ip_button">5</button>

gallery_next()函数;被封装并像这样:

this.gallery_next = function() {
if (galleryRotating) { return; }
galleryRotating = true;
var elem = $(galleryId + " > li").first();
$(galleryId).append(elem.clone());
$(galleryId).animate({"left" : -imgWidth}, 650, function() {
elem.remove();
galleryRotating = false;
$(galleryId).css({"left" : 0});
});

最佳答案

animate 不会在 for 循环再次调用该函数时完成,因此 galleryRotation 仍为真,函数将没做什么。您需要一种不同的方法:要么设置一个计时器以在 700 毫秒内调用您的函数,要么(更好)在传递给 animate 的回调中再次调用旋转。

关于javascript - 通过for循环迭代函数x次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15410441/

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