【问题标题】:How to make a carouFredSel autoplay and sync?如何使 carouFredSel 自动播放和同步?
【发布时间】:2016-01-25 07:51:36
【问题描述】:

我有旋转木马(我认为它是由引导程序制成的),它是从 themeforest 的模板中派生的。在我想让它自动播放之前它运行良好。我试过设置interval:1000,但还是不行。这是脚本:

function InitPropertyCarousel() {
    if ($('.carousel.property .content li img').length !== 0) {
        $('.carousel.property .content li img').on({
            click: function(e) {
                var src = $(this).attr('src');
                var img = $(this).closest('.carousel.property').find('.preview img');
                img.attr('src', src);
                $('.carousel.property .content li').each(function() {
                    $(this).removeClass('active');
                });
                $(this).closest('li').addClass('active');
            }
        });
    }
}

这是示例链接:http://preview.byaviators.com/template/realia/detail.html。 (我尝试将此代码放在 jsfiddle 上,但它不起作用。)

【问题讨论】:

  • 你可以在这篇帖子stackoverflow.com/questions/13525258/… ;) 中找到解决方案
  • 感谢您的文字,但是您阅读了我的详细信息吗?代码完全不同,您的链接没有帮助:(
  • 能让你成为小提琴吗?
  • 你现在需要在你的函数上设置间隔。 setInterval(function(){ InitPropertyCarousel() }, 3000);
  • 是的,它会移动缩略图条。但它不会改变preview 类中的主照片。

标签: javascript jquery css twitter-bootstrap carousel


【解决方案1】:

我认为您正在使用此轮播carouFredSell。而真正的初始化代码是这样的:

function InitCarousel() {
if ($('#main .carousel .content ul').length !== 0) {
    $('#main .carousel .content ul').carouFredSel({
        scroll: {
            items: 1
        },
        auto: false,
        next: {
            button: '#main .carousel-next',
            key: 'right'
        },
        prev: {
            button: '#main .carousel-prev',
            key: 'left'
        },
        //try if this fires after slide event ends
        onAfter: function () {
            var src = $(this).find('img').attr('src');
            var img = $(this).closest('.carousel.property').find('.preview img');
            img.attr('src', src);
            $('.carousel.property .content li').each(function() {
                $(this).removeClass('active');
            });
            $(this).closest('li').addClass('active');
        }
    });
}

if ($('.carousel-wrapper .content ul').length !== 0) {
    $('.carousel-wrapper .content ul').carouFredSel({
        scroll: {
            items: 1
        },
        auto: false,
        next: {
            button: '.carousel-wrapper .carousel-next',
            key: 'right'
        },
        prev: {
            button: '.carousel-wrapper .carousel-prev',
            key: 'left'
        }
    });
}
}

你有选项auto:false,尝试将它设置为'true`。如果这是您使用的滑块,您可以从上面的链接中查看文档。

【讨论】:

  • 感谢您的提示,我希望它可以告诉我一些功能或插件名称。所以我可以猜到它是什么。但它不是carouFredSell :(
  • 因为在你的主题的 js 文件夹中你有这个文件carousel.js,从那里我发现这是carouFredSell。然后在realia.js这个函数InitCarousel()被调用,在这个函数中,据我所见,这些ul被选中。因此我决定,这是正确的功能和正确的轮播:(。
  • 这个函数InitPropertyCarouselclick事件绑定到你在底部轮播的图片上,这个有5张图片,点击到他的图片后,在大的图片中改变图片。如果您愿意,请尝试评论此功能,如果您这样做,那么您应该无法单击底部轮播上的图像。然后您可以尝试将一些console.log() 放入InitCarousel 函数中以确保它运行。然后您还可以评论InitCarousel 以检查您的轮播是否已初始化。如果否 - 这是初始化函数,否则,尝试从所有函数中 console 以检查哪些运行。
  • 您在div 之前的class="caroufredsel_wrapper" 元素上还有class="caroufredsel_wrapper"。您有一些使用引导滑块功能的.prise_slider。作为建议,您可以评论realia.js文件中的所有功能,并一一取消注释,重新加载网站,找到您需要的功能:)
  • 我通过在第一个轮播中添加一些额外的代码(onAfter 回调)来更新我的答案,但你可以尝试两者,看看放在哪里。我不能更具体,我在不使用真实代码的情况下,不能 100% 确定准确的语义,但关键是您必须找到正确的方法来添加必须在“onAfter”事件上执行的函数。我认为这一定没问题,但如果不是,请检查文档。如果您仍然有问题,请在某个地方创建fiddle,并在此处或聊天中向我发送指向它的链接,我会尽力帮助您:)
猜你喜欢
  • 2014-04-21
  • 1970-01-01
  • 2013-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-27
  • 1970-01-01
相关资源
最近更新 更多