I am trying to understand how to count and display current and total number of figures on my page.
My html
<div class="is-vertical">
<figure><img src="src.jpg"><figcaption class="wp-element-caption">Towers Day<br>NYC</figcaption></figure>
<figure><img src="src.jpg"><figcaption class="wp-element-caption">Towers Day<br>NYC</figcaption></figure>
<figure><img src="src.jpg"><figcaption class="wp-element-caption">Towers Day<br>NYC</figcaption></figure>
</div>
My js attempt of trying to get the total number
var totalItems = $( ".is-vertical figure" ).length;
My js attempt of trying to display the variable in an appended span
$('.is-vertical').append('<span class="numbers">')+totalItems.join('</span>');
});
For the last part of showing the current one I am wondering if one could use ($(window).scrollTop() somehow and update the value of the current figure in view.
2
Answers
It ended up solved by this script:
To construct a jQuery element, you need the following structure:
Alternatively:
Working example