Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery waypoints using multiple classes

I'm using http://imakewebthings.com/jquery-waypoints and having 5 classes (staffmember), at the moment waypoints fires on all the classes at once when getting the first class. How to stage it so that I can add as you pass through the list?

<ul id="staff">
<li class="staffmember"></li>
    <li class="staffmember"></li>
    <li class="staffmember"></li>
    <li class="staffmember"></li>
    <li class="staffmember"></li>
</ul>

jQuery

$('.staffmember').waypoint(function(direction) {
jQuery('.staffmember').addClass('on').next();
});

Thanks

like image 363
flvll Avatar asked Jun 05 '14 12:06

flvll


People also ask

How to select an element with multiple classes using jQuery?

There are two procedures to select an element with multiple classes by using jQuery. Both the procedures are described below with the proper example. Using filter () Method: By using filter () method we can filter out all the elements that do not match the selected criteria and those matches will be returned.

How do you manipulate CSS in jQuery?

jQuery Manipulating CSS. jQuery has several methods for CSS manipulation. We will look at the following methods: addClass() - Adds one or more classes to the selected elements. removeClass() - Removes one or more classes from the selected elements. toggleClass() - Toggles between adding/removing classes from the selected elements.

How do I specify multiple classes for a class attribute?

You can also specify multiple classes within the addClass () method: The following example shows how to remove a specific class attribute from different elements: The following example will show how to use the jQuery toggleClass () method.

What is an array of waypoints?

In the example above, waypoints will be an array of Waypoint instances, one for each of the elements matching the selector. In this case, an array containing only one waypoint using the lone #options-only element. Notice that the element option is no longer needed with the jQuery or Zepto builds, as elements are provided by the matched selector.


Video Answer


1 Answers

If I understand you correctly try this. It should iterate through each .waypoint element and add individual waypoints to each one that add the .on class as you scroll past them.

$('.staffmember').each(function() {
  $(this).waypoint(function() {
    $(this).addClass('on');
  });
});
like image 171
Ennui Avatar answered Oct 02 '22 13:10

Ennui