简体   繁体   English

Javascript / Jquery元素轮播

[英]Javascript/Jquery element carousel

I am trying to make a javascript/jquery carousel. 我正在尝试制作javascript / jquery轮播。 I have an unordered list and inside the ulist i have more lists. 我有一个无序列表,而在溃疡病患者中,我还有更多列表。 I get the first lit with: 我第一次亮起:

list = $(wrapper).find("li:eq(0)").show()

On the button-next down i want it to show next list so it would be: 在下一个按钮上,我希望它显示下一个列表,因此它将是:

list = $(wrapper).find("li:eq(1)").show()

on the button-previous i want the list to show previous list. 在上一个按钮上,我希望列表显示上一个列表。 How could I achieve something like this, to append ("li:eg(x+1/x-1)).show() 我怎样才能实现这样的事情,以追加("li:eg(x+1/x-1)).show()

Introduce a variable to keep track of the current list. 引入变量以跟踪当前列表。 When a user clicks the next button, increment it by one, and vice-versa for when previous is clicked. 当用户单击下一个按钮时,将其增加一个,反之亦然。 Then use this variable in your selector. 然后在选择器中使用此变量。

list = $(wrapper).find("li:eq("+ currentList +")").show()

Sidenote: You might want to introduce some bounds checking so currentList never goes below 0 and never exceeds the number of lists you have available. 旁注:您可能想引入一些边界检查,以使currentList永远不会低于0且永远不会超过可用列表的数量。

//On previous click
if(currentList - 1 > 0){
  //do something
}


//assign a variable to keep track of the upper bounds
var maxList = $(wrapper).find('li').length;

//On next click
if(currentList + 1 < maxList - 1){
  //do something
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM