如果滑块从头开始,Coda-Slider 不应滑回所有元素

发布于 2024-12-12 18:09:23 字数 1221 浏览 0 评论 0原文

我正在使用 coda-slider 就像示例 2 中一样。现在我不如果滑块位于最后一个元素上,则不希望滑块回退到第一个元素。我希望滑块仅沿正确的方向移动(当然从第一个元素开始)。

coda 滑块似乎使用了 jQuery animate 函数:

    function autoSlide() {
        if (navClicks == 0 || !settings.autoSlideStopWhenClicked) {
            if (currentPanel == panelCount) {
                var offset = 0;
                currentPanel = 1;
            } else {
                var offset = - (panelWidth*currentPanel);
                currentPanel += 1;
            };
            alterPanelHeight(currentPanel - 1);
            // Switch the current tab:
            slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current');
            // Slide:
            $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
            setTimeout(autoSlide,settings.autoSlideInterval);
        };
    };

animate 函数中的参数是否有可能完成这项工作?

coda滑块本身仅支持此参数

I'm using the coda-slider like in example 2. Now I don't want the behavior that the slider rewinds back to the first element if it is on the last element. I want that the slider only moves in the right direction (and of course starts with the first element).

The coda slider seems to use the jQuery animate function:

    function autoSlide() {
        if (navClicks == 0 || !settings.autoSlideStopWhenClicked) {
            if (currentPanel == panelCount) {
                var offset = 0;
                currentPanel = 1;
            } else {
                var offset = - (panelWidth*currentPanel);
                currentPanel += 1;
            };
            alterPanelHeight(currentPanel - 1);
            // Switch the current tab:
            slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current');
            // Slide:
            $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
            setTimeout(autoSlide,settings.autoSlideInterval);
        };
    };

Are there any chances that a parameter in the animate function will do the job?

The coda slider itself only supports this parameters.

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

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

发布评论

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

评论(2

跨年 2024-12-19 18:09:23

Coda Slider 使用serialScroll。如果您不希望滑块到达末尾后返回到第一个元素,请打开 jquery.serialScroll 文件(jquery.serialScroll-1.2.1.js),转到第 37 行并将循环从“true”更改为“true”为“假”。

cycle:false, //cycle endlessly ( constant velocity )

The Coda Slider uses serialScroll. If you do not want the slider to go back to the first element after it reaches the end, open the jquery.serialScroll file (jquery.serialScroll-1.2.1.js), go to line 37 and change the cycle from “true” to “false”.

cycle:false, //cycle endlessly ( constant velocity )
顾铮苏瑾 2024-12-19 18:09:23

我注意到这个有点旧了,但我自己也遇到了这个问题,并想发布我是如何做到的,以防其他人也需要这样做。

因此,我们需要做的第一件事是创建第一个面板的额外副本并将其放置在面板容器的末尾。这必须在我们调用容器上的 codaSlider 之前完成。您还需要对拥有的面板数量进行硬编码。那么...

$(document).ready(function(){
    $('.panel-container .panel').eq(0).clone().appendTo('.panel-container');
    $("#main-photo-slider").codaSlider();
});

然后,将 autoslide() 函数更改为:

function autoSlide() {
    if (navClicks == 0 || !settings.autoSlideStopWhenClicked) {
        if (currentPanel == panelCount) {
            $('.panelContainer').css({'left':'0px'});
            var offset = 1;
            currentPanel = 2;
        } else {
            var offset = - (panelWidth*currentPanel);
            currentPanel += 1;
        };
        alterPanelHeight(currentPanel - 1);
        // Switch the current tab:
        slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current');
        // Slide:
        $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
        setTimeout(autoSlide,settings.autoSlideInterval);
    };
};

这应该可以工作,但可能会产生一些不良结果,例如,如果您使用导航栏,它会创建一个指向最后一个的额外链接图像,当下一个/上一个按钮位于最后一个/第一个图像上时,这与下一个/上一个按钮的情况相同...这对我来说不是问题,因为我使用了此处讨论的自定义导航:
http://css-tricks.com/creating- a-slick-auto-playing-featured-content-slider/

I noticed this one is a bit old, but I ran into this problem myself and wanted to post how I did it, in case someone else needs to do this also.

So the first thing we need to do is create an extra copy of our first panel and place it at the end of the panel container. This must be done BEFORE we call the codaSlider on our container. You will also need to hardcode the amount of panels you have. So...

$(document).ready(function(){
    $('.panel-container .panel').eq(0).clone().appendTo('.panel-container');
    $("#main-photo-slider").codaSlider();
});

Then, change the autoslide() function to:

function autoSlide() {
    if (navClicks == 0 || !settings.autoSlideStopWhenClicked) {
        if (currentPanel == panelCount) {
            $('.panelContainer').css({'left':'0px'});
            var offset = 1;
            currentPanel = 2;
        } else {
            var offset = - (panelWidth*currentPanel);
            currentPanel += 1;
        };
        alterPanelHeight(currentPanel - 1);
        // Switch the current tab:
        slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current');
        // Slide:
        $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
        setTimeout(autoSlide,settings.autoSlideInterval);
    };
};

That should work, but it could produce some undesireable results, for example if you use the Nav bar it would create an extra link to the last image, this would be the same case with the Next/Prev buttons when they are over the last/first image... this was not an issue for me because I used a custom Nav that's talked about here:
http://css-tricks.com/creating-a-slick-auto-playing-featured-content-slider/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文