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

Once:false #3

Open
Geestig opened this issue Sep 7, 2018 · 5 comments
Open

Once:false #3

Geestig opened this issue Sep 7, 2018 · 5 comments

Comments

@Geestig
Copy link

Geestig commented Sep 7, 2018

When using once:false with slide-up slide-down it can cause the image to go in an infinite loop because the class keeps getting removed and added again since the image is on the border of the screen.

const onIntersection = (entries, observer) => {
  entries.forEach((entry) => {
    if (entry.intersectionRatio >= options.threshold) {
      animate(entry.target);

      if (options.once) {
         observer.unobserve(entry.target);
      }
    } else if (!options.once) {
      reverse(entry.target);
     }
   });
 };

Part that causes the issue.

EDIT: removed image cause it showed nothing decent. Great little library btw!

EDIT EDIT: i meant ONCE:FALSE !!!

@mciastek
Copy link
Owner

mciastek commented Sep 7, 2018

Thanks for catching this bug! It looks like wrong threshold setting and I need to confirm it. I'll be back with patch as soon as possible.

@Geestig Geestig changed the title Once:true Once:false Sep 7, 2018
@Geestig
Copy link
Author

Geestig commented Sep 7, 2018

After trying out some fixes it seems you have to offset the threshold by 20% to make up for the translateY, not 100% working yet though.

@mciastek
Copy link
Owner

mciastek commented Sep 9, 2018

I did a test and it looks like there is a problem with translation itself. Basically, when element is shifted by 20% of it's size, threshold (with value 0.5) doesn't match the center point of the element. Solution here is to either animate only when the animation has ended or apply new threshold for shifted elements. I will think about a fix for this problem.

@Geestig
Copy link
Author

Geestig commented Sep 14, 2018

@mciastek any updates on how to solve this?

@mciastek
Copy link
Owner

mciastek commented Sep 26, 2018

I checked this bug and I need to find a way how to resolve it without adding too much complexity to sal.js. To fix this I would need to let sal know how certain element was translated and update the threshold accordingly.

Here's a workaround for this problem. As Intersection Observer detects if specific amount of pixels are present in viewport, every time you translate the element, it's pixels are also translated. So to bypass this behaviour you need to wrap this element in a wrapper, which will be detected by sal. Next you need to disable animations on the wrapper. Then you can apply animation to proper element. Here's a simple demo - https://codesandbox.io/s/nkolnk00n0.

I will try to come up with solution, but I'm open to any ideas.

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

2 participants