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

I can't get force feeding to work #422

Closed
ccorcos opened this issue Jan 28, 2015 · 10 comments
Closed

I can't get force feeding to work #422

ccorcos opened this issue Jan 28, 2015 · 10 comments

Comments

@ccorcos
Copy link

ccorcos commented Jan 28, 2015

This doesnt work...

    $node.insertBefore(next)
      .velocity {translateX: ['0%', '100%']},
        duration: 500
        easing: 'ease-in-out'
        queue: false

It only works when I use a hook:

    $.Velocity.hook($node, "translateX", "100%");
    $node.insertBefore(next)
      .velocity {translateX: '0%'},
        duration: 500
        easing: 'ease-in-out'
        queue: false

Am I missing something?

@ccorcos
Copy link
Author

ccorcos commented Jan 28, 2015

Ok. So I've fiddled around a little more ;)

Force-feeding works. But on certain browsers (every time with firefox, sometimes with Safari, never with Chrome), you'll see a brief flash when the element is inserted before velocity catches it and moves it.

For example, check out the slide left button on this demo: http://transition-demo.meteor.com/

P.S. I'm using velocity to make a much needed page transitioning package for meteor: https://github.com/ccorcos/meteor-transitioner

And great job with this framework.

@ccorcos
Copy link
Author

ccorcos commented Jan 29, 2015

Ok. Here we go:

Here's the code:
https://gist.github.com/anonymous/23f0f73678bc81354908

and here it is on CodePen:
http://codepen.io/ccorcos/pen/gbxGpZ

You'll notice there is a flash of red when you press the button

@ydaniv
Copy link
Contributor

ydaniv commented Jan 29, 2015

@ccorcos that's because how you're inserting the second page into the DOM dynamically on click. Try giving us a clean example where the elements are present in the DOM before you move them around with Velocity.
To be more specific, it's probably due to the fact you're inserting an element that's initially in view when inserted.

@ccorcos
Copy link
Author

ccorcos commented Jan 29, 2015

Yeah, I see. The problem for me is that this is the way meteor works. I'm given and insert and remove function and I need to to insert it into the dom and do this animation. The odd thing is that any of the built-in effects don't have this flickering problem:

https://github.com/julianshapiro/velocity/blob/master/velocity.ui.js#L535

But the ones I wrote do have this problem:

$.Velocity.RegisterEffect 'transition.pushRightIn', 
  defaultDuration: 500,
  calls: [
    [{translateX: ['0%', '100%'], translateZ: 0, easing: "ease-in-out"}]
  ]

$.Velocity.RegisterEffect 'transition.pushLeftOut', 
  defaultDuration: 500,
  calls: [
    [{translateX: ['-100%', '0%'], translateZ: 0, easing: "ease-in-out"}]
  ]

Notice the difference between slideLeft and slideRight in this demo: http://transition-demo.meteor.com

Any ideas?

@julianshapiro
Copy link
Owner

Taking a look now.

@julianshapiro
Copy link
Owner

The UI pack addresses the flashing by immediately setting opacity upfront: https://github.com/julianshapiro/velocity/blob/master/velocity.ui.js#L134.

I would try doing that with your code as well. Let me know how that works out.

@ccorcos
Copy link
Author

ccorcos commented Feb 16, 2015

Interesting. I see whats going on here. Every effect animates opacity. Is it possible to immediately animate the opacity to prevent the flash?

Here's what I have going right now...

$.Velocity.RegisterEffect('transition.pushRightIn', {
  defaultDuration: 500,
  calls: [
    [
      {
        translateX: ['0%', '100%'],
        translateZ: 0,
        easing: "ease-in-out"
      }
    ]
  ]
});

@julianshapiro
Copy link
Owner

oh shit, you're right! it's because you have to explicitly animate opacity in there. either throw it in as a dummy property (E.g. opacity: [ 1, 1]) or manually set opacity to 0 before the animation begins

@ccorcos
Copy link
Author

ccorcos commented Feb 17, 2015

Much better! That works. Thanks.

@az-iB
Copy link

az-iB commented Mar 30, 2016

i suggest to remove the style attribute after the transition complete

var start = '100%'; $.Velocity.hook(node, 'translateX', start); $(node) .insertBefore(next) .velocity({translateX: [0, start]}, { duration: ANIMATION_DURATION, easing: 'ease-in-out', queue: false, complete: function() { $(node).removeAttr("style"); } });

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

4 participants