javascript carouFredSel:为下一个/上一个按钮创建一个函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9540515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
carouFredSel: Create a function for next / prev buttons?
提问by colindunn
I'm using carouFredSelto create multiple carousels on the same page. If you look at this JSFiddleyou will see that there are two carousels, but only one is able to be scrolled with the next / prev buttons.
我正在使用carouFredSel在同一页面上创建多个轮播。如果您查看此JSFiddle,您会看到有两个轮播,但只有一个可以使用下一个 / 上一个按钮滚动。
Without adding a class or ID, I am trying to tell the buttons to only scroll the corresponding carousel. I believe this be accomplished with a function, but I'm not entirely sure how. Something like this:
在不添加类或 ID 的情况下,我试图告诉按钮仅滚动相应的轮播。我相信这可以通过一个函数来完成,但我不完全确定如何。像这样的东西:
prev: {
button: function() {
$(this).next('.prev');
}
},
回答by Eric Hodonsky
Give this a look, it's right in the documentation:
看看这个,它在文档中是正确的:
prev: {
button: function() {
return $(this).parent().siblings(".prev");
}
},
next: {
button: function() {
return $(this).parent().siblings(".next");
}
}
oh and notice, I took out the key
, because then you would have to have the carousels synchronized... and you can have one or the other, not both. (unless you conditionally assigned keys, but there goes your small code)
--
http://caroufredsel.frebsite.nl/code-examples/configuration.phpsearch: "Get the HTML-elements for the buttons and the container dynamically"
哦,请注意,我取出了key
,因为那样你就必须同步传送带......而且你可以拥有一个或另一个,而不是两个。(除非你有条件地分配了键,但你的小代码会出现)
--
http://caroufredsel.frebsite.nl/code-examples/configuration.php搜索:“动态获取按钮和容器的 HTML 元素”
回答by Brightweb
I think thats better set an ID.
我认为最好设置一个ID。
$("#list1").carouFredSel({
direction: "up",
auto : false,
items: 3,
prev : "#prev1",
next : "#next1"
});
$("#list2").carouFredSel({
direction: "up",
auto : false,
items: 3,
prev : "#prev2",
next : "#next2"
});
回答by Sangeet Shah
may be this one is usefull for you.in my page its workin good.
可能这个对你有用。在我的页面中它工作良好。
prev: {
button : ".prev"
},
next: {
button : ".next"
},