我正在使用 jQuery 轮播,从这里下载: http://www.thomaslanciaux.pro/jquery/ jquery_carousel.htm
它使用分页,并在单击页码时将一个名为“active”的类应用于当前页码。我想在应用此类时触发一个事件,因为它还使用左右箭头将该类应用于当前页码。
这是我希望在应用类时触发的事件:
$('.red').click(function() {
$('#formred').attr('checked', 'checked');
});
我已经让它工作,但仅在页面加载时:
if ($('.red').hasClass('active')) {
$('.red').trigger('click');
}
第一个页码默认应用了该类,这就是为什么它在页面加载时起作用。当该类应用于其他页码时,我需要发生这种情况。
I am using a jQuery carousel, downloaded from here: http://www.thomaslanciaux.pro/jquery/jquery_carousel.htm
It uses pagination, and applies a class called "active" to the current page number when the page number is clicked. I want to trigger an event to happen when this class is applied, since it also uses left and right arrows to apply the class to the current page number.
Here's the event that I want to be triggered when the class is applied:
$('.red').click(function() {
$('#formred').attr('checked', 'checked');
});
I have gotten it to work, but only when the page loads:
if ($('.red').hasClass('active')) {
$('.red').trigger('click');
}
The first page number has the class applied by default, which is why this works when the page loads. I need this to happen as the class is applied to other page numbers.
发布评论
评论(3)
编辑:如果您只是在单击按钮时需要它,而不是其
auto
功能,则只需放置一个.delegate()
一旦可用,就可以在.carousel
上侦听'a[role=button]'
元素上的click
事件。同样,这仅适用于按钮上的单击事件,如果设置为自动旋转则无效。不确定这是否是您所追求的。
如果需要,有一个名为
livequery
的插件,它将通过 jQuery 在 DOM 修改上运行代码。http://brandonaaron.net/code/livequery/docs
如果传递第二个函数参数,当类(或元素)被删除时它将运行。
EDIT: If you're just needing it on button clicks, and not for its
auto
feature, you could just place a.delegate()
on the.carousel
once it's available that listens forclick
events on the'a[role=button]'
elements.Again, this would only work for click events on the buttons, not if it is set up to
auto
rotate. Not sure if this is what you're after.If need be, there's a plugin called
livequery
that will run code on DOM modifications via jQuery.http://brandonaaron.net/code/livequery/docs
If you pass a second function argument, it will run when the class (or element) is removed.
您不能创建一个共享事件处理程序,例如:
然后将此事件设置为单击和按键:
Couldn't you create a shared event handler, like:
And then set this event to both click and keydown:
我要做的是:
1-禁用自动播放
2-创建一个setInterval,在轮播的分页上执行触发(“单击”)
3-当然,在其中您可以做更多的事情,而不仅仅是触发幻灯片
What I would do is :
1-disable autoplay
2-create a setInterval that does a trigger('click') on the pagination of the carousel
3-and of course inside that you could do more then just trigger the slides