How to use / count jQuery.find ()

I am using the jQuery plugin that I found here: http://tutorialzine.com/2011/03/photography-portfolio-shutter-effect/ , but I changed it a bit.

It still works fine in the way it is supposed to, but I added the next button, which the custom cna uses to go to the next image, and then stops the interval for one loop so as not to change the next image too quickly.

However, my problem is the scroll button. I'm not sure how to do this, so I added a variable

var positionInt 

which is the position of the last element of the list, so I know where I am in the list.

How to use this together with the li object created by this line:

 var container = $('#container'), li = container.find('li'); 

to open the correct li element?

Also, how can I find the length of an object li? I tried li.size (), li.count () and li.length and did not work.

Or is there a way using only the .find () method to open the li element in front of the currently visible one? Here's how it happens initially: forward :

 li.filter(':visible:first').hide(); // Hid the only visible li if(li.filter(':visible').length == 0){ li.show(); // if nothing is visible load a li (Im not really sure what this is pointing at, but it loads the next li) } 

Greetings

+4
source share
2 answers

You can get the number li as:

 var nr_li = $("#container ul li").length; 

If you know the current index of the <li> currently in use, you can get the previous one by doing:

 $prev_li = $("#container ul li:eq(" + (index-1) + ")"); 

Make sure you do some calculations and check this index-1 to make sure you are not going beyond and trying to achieve a better element.

Another thing you can do is loop through <li> and add each one to an array, for example. Then you can just pull the previous one from your array.

 var array_li = new Array(); $('#container li').each(function() { array_li.push($(this)); }); 
+12
source

Both length and size() will work to count the number of elements in a jquery object.

http://jsfiddle.net/KeKPb/

I find that length used more often since there is no need for the overhead of calling size() when everything it does always uses length inside.

You will need to determine what โ€œnot workingโ€ means, because both methods are perfectly correct.

+4
source

Source: https://habr.com/ru/post/1389348/


All Articles