Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

trigger doIn() only once per element #29

Closed
oozrafa opened this issue Dec 10, 2015 · 2 comments
Closed

trigger doIn() only once per element #29

oozrafa opened this issue Dec 10, 2015 · 2 comments

Comments

@oozrafa
Copy link

oozrafa commented Dec 10, 2015

Is there any way to remove onScreen from a specific element?
For example, my page is divided into sections and they all have the same class 'log_entered_viewport'. What I want is that only the first time they enter the viewport that onScreen will be triggered and I will log the event. If the users scrolls up and down the page and the particular section enters the viewport, then I only want it to be triggered once.

@oozrafa
Copy link
Author

oozrafa commented Dec 10, 2015

That was quick :) Solved it by adding a 'logged' class to the element and then checking for the class.
In other words, it's like the 'toggleClass' option, except that the class is removed.

doIn: function() {

        $e = $(this);

        if ( !$e.hasClass('logged') ){

            // -- code to log that the element has entered the viewport

                            // add the class the mark that the element has been logged
            $e.addClass('logged');

        }

   }

@silvestreh
Copy link
Owner

heh, I was going to suggest something along those lines

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants