jcarousellite 点击停止

发布于 2024-10-30 22:17:57 字数 493 浏览 3 评论 0原文

你好 我有一个包含 jcarousellite 的页面,显示一些图像并每 5 秒自动滚动一次,当我单击轮播中的任何图像时,我想停止滚动,

这就是我想要做的

$(document).ready(function() {
    $('.slider_images').jCarouselLite({
        btnNext: "#next",
        btnPrev: "#prev",
        auto:  3000         
    }); 

    $(".slider_images img").click(function(){


        $('.slider_images').jCarouselLite({
            btnNext: "#next",
            btnPrev: "#prev",
            scroll: false       
        }); 


    });
});

hi
i have a page with jcarousellite showing some images and scrolling auto after every 5 seconds i want to stop the scroll when i click on any image in carousel

here is what i am trying to do

$(document).ready(function() {
    $('.slider_images').jCarouselLite({
        btnNext: "#next",
        btnPrev: "#prev",
        auto:  3000         
    }); 

    $(".slider_images img").click(function(){


        $('.slider_images').jCarouselLite({
            btnNext: "#next",
            btnPrev: "#prev",
            scroll: false       
        }); 


    });
});

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

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

发布评论

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

评论(6

一瞬间的火花 2024-11-06 22:17:57

我很抱歉这么晚才回复。我的问题解决了。我们可以通过改变jcarousellite的pauseOnHover选项很容易地实现点击停止属性。如果你看到pauseOnHover的实现,它是这样的:

o.pauseOnHover ? ul.hover(function (){ paused == 1 }, function (){paused=0}) : "";

我们可以通过将ul.hover更改为ul.click来实现点击停止

o.pauseOnHover ? ul.click(function (){ paused == 1 }, function (){paused=0}) : "";

。祝你有美好的一天。

I am so sorry for very late response. My problem was solved. We can achieve stop on click property very easily by changing pauseOnHover option of jcarousellite. If you see the implementation of pauseOnHover, its something like this:

o.pauseOnHover ? ul.hover(function (){ paused == 1 }, function (){paused=0}) : "";

we can achieve stop on click by changing ul.hover to ul.click

o.pauseOnHover ? ul.click(function (){ paused == 1 }, function (){paused=0}) : "";

Have a Nice Day.

独自唱情﹋歌 2024-11-06 22:17:57

我读了一会儿代码,发现自动滚动是通过使用setTimeout实现的:

if(o.auto)
    setInterval(function() {
        go(curr+o.scroll);
    }, o.auto+o.speed);

如果你第二次使用jCarouselLite,它不会停止>设置超时。要停止 setTimout,您必须调用 window.clearTimeout

var timeoutId = window.setTimeout(function(){...}, 100);

window.clearTimeout(timeoutId);

这是不可能的,因为 jcarousel 的代码没有为您提供这些 timeoutId。您可以与开发人员交谈或自行修改代码。

i read the code for a while and found out that the auto scrolling is implemented by using a setTimeout:

if(o.auto)
    setInterval(function() {
        go(curr+o.scroll);
    }, o.auto+o.speed);

If you use jCarouselLite a second time it won't stop the setTimeout. To stop a setTimout you have to invoke window.clearTimeout:

var timeoutId = window.setTimeout(function(){...}, 100);

window.clearTimeout(timeoutId);

This is impossible since the code of jcarousel didn't provide you with these timeoutId. You can talk to the developer or modify the code on your own.

阿楠 2024-11-06 22:17:57

我想不同意 scheffield 和/或找到使用此插件的解决方案,但我必须同意他的观点- 需要重写源代码才能完成您想要的操作。或者,您可能需要考虑 jquery 循环。它已经有“暂停”和“停止”方法。

I wanted to disagree with scheffield and/or find a work around using this plug-in, but I have to agree with him - it would take a rewriting of the source to do what you wanted. Alternatively, you may want to consider jquery cycle. It has 'pause' and 'stop' methods already there.

找个人就嫁了吧 2024-11-06 22:17:57

的顶部

var timers = new Array();

将其添加到文件更改

setInterval(function(){go(curr+o.scroll)},o.auto+o.speed)  

timers.push(new Array( this.className, setInterval(function(){go(curr+o.scroll)},o.auto+o.speed)));

停止滚动

var classToStop = ".TestClass"; 

for(var i=0; i < timers.length; i++)
{
    if("."+timers[i][0] == uploadifyClass)
    window.clearInterval(timers[i][1])
}

Add this to the top of the file

var timers = new Array();

change

setInterval(function(){go(curr+o.scroll)},o.auto+o.speed)  

to

timers.push(new Array( this.className, setInterval(function(){go(curr+o.scroll)},o.auto+o.speed)));

to stop a scroll

var classToStop = ".TestClass"; 

for(var i=0; i < timers.length; i++)
{
    if("."+timers[i][0] == uploadifyClass)
    window.clearInterval(timers[i][1])
}
复古式 2024-11-06 22:17:57

这将停止页面上的所有轮播自动前进。我正在杀死这里使用超时的所有内容。这对我有用:

$(".slider_images img").click(function(){
    var x = setTimeout("");
    for (var i = 0 ; i < x ; i++)
    clearTimeout(i);
}

This will stop all carousels auto progression on the page. I am killing everything that is using a timeout here. This worked for me:

$(".slider_images img").click(function(){
    var x = setTimeout("");
    for (var i = 0 ; i < x ; i++)
    clearTimeout(i);
}
如日中天 2024-11-06 22:17:57
$(".mycarousel").trigger('stopCarousel');

如果您使用的是最新的 jcarousel https://github.com/kswedberg/jquery-carousel- lite/

由于某种原因,此事件不在他们的文档中,尽管暂停Carousel 是。

$(".mycarousel").trigger('stopCarousel');

If you're using the newest jcarousel https://github.com/kswedberg/jquery-carousel-lite/

This event isn't in their documentation for some reason although pauseCarousel is.

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