Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom event on viewport visible? #36

Closed
IndexOverflow opened this issue Mar 13, 2014 · 8 comments
Closed

Custom event on viewport visible? #36

IndexOverflow opened this issue Mar 13, 2014 · 8 comments

Comments

@IndexOverflow
Copy link

A great addition to scrollReveal would be the ability to trigger your own JS events on viewport visibility.

@jlmakes
Copy link
Owner

jlmakes commented Mar 13, 2014

I like it.

Any ideas on how you see this working? Perhaps something like:

<div data-scroll-reveal="enter left and emit evt-name"> foo </div>

I think there should be an event fired when an element enters the viewport, and when it leaves — meaning the above would trigger the events evt-name--enter and evt-name--exit respectively.

Thoughts?

@IndexOverflow
Copy link
Author

Cool. Your suggestion sounds good too: I've only used scrollReveal for a short while, so I'm not familiar with the underlying code, but from a users standpoint keeping the current sugar syntax makes sense.

Is it likely that you will implement this yourself anytime soon or should I give it a go and make a pull request?

@jlmakes
Copy link
Owner

jlmakes commented Mar 13, 2014

Duplicate #19 #44

I’ll likely start on integrating #30 and #32 next, so if you want to take a stab at adding custom event emitters — please do.

@IndexOverflow
Copy link
Author

I've made a working prototype. Working on this I've discovered several possible approaches. Problem is that I sort of like all of them. Hoping to get some feedback.

  1. Pass in function names and call them on enter and exit respectivily.
    For example,
<div data-scroll-reveal="enter left and notify someFunction, exit otherFunction"> foo </div>
window.someFunction = function(el) {// Function body};

This would deviate a bit from my original post, but does allow a lot of flexibility.

  1. Create a scrollReveal global event on enter / exit.
<div id="somediv" data-scroll-reveal="enter left"> bar </div>
$('#somediv').on('scrollReveal', function(e) {
  var el = e.target;
});
  1. The original, suggested approach. Emitting event with postfixed --enter or --exit.

@jlmakes
Copy link
Owner

jlmakes commented Mar 14, 2014

Nice work Knut, I’ll review and get back to you over the weekend. (It’d be nice if we had some more input from others on this too!)

@jlmakes
Copy link
Owner

jlmakes commented Mar 22, 2014

Thanks for the ideas @IndexOverflow !

Callbacks are now supported in v2.x.xSee the Wiki

@Alaamasoud
Copy link

Hi,
can you please explain how it's possible to trigger the animation when element exit the viewport?

thanks in advance

@jlmakes
Copy link
Owner

jlmakes commented Feb 20, 2019

@Alaamasoud you would have to use options.afterReset

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

No branches or pull requests

3 participants