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

Update range on window resize? #8

Open
ndimatteo opened this issue Jan 6, 2017 · 0 comments
Open

Update range on window resize? #8

ndimatteo opened this issue Jan 6, 2017 · 0 comments

Comments

@ndimatteo
Copy link

ndimatteo commented Jan 6, 2017

I'm doing the following to handle updating animations on window resize:

var Choreographer = require('choreographer-js');

var obj_anim = [
  {
    range: [-1, 500],
    selector: '.object',
    type: 'scale',
    style: 'transform:translateY',
    from: 100,
    to: 0,
    unit: '%'
  },
  {
    range: [document.getElementById('trigger').getBoundingClientRect().top + window.scrollY, document.getElementById('trigger').getBoundingClientRect().top + window.scrollY + 300],
    selector: '.object',
    type: 'scale',
    style: 'left',
    from: 50,
    to: -50,
    unit: '%'
  }
];

var choreographer = new Choreographer({
  animations: obj_anim
});

window.addEventListener('scroll', function() {
  choreographer.runAnimationsAt(window.pageYOffset);
});

window.addEventListener('resize', function() {
  choreographer.updateAnimations(obj_anim);
});

However the animation doesn't begin when the trigger element hits the top of the page as expected unless I hard refresh. It doesn't seem to be respecting the range I've set.

I can confirm that the distance from the top of the document to the top of the trigger element is accurate on resize, so what am I missing here?

Thanks!

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

No branches or pull requests

1 participant