[ 6 posts ]

Rick Wassing

  • Username: Rick Wassing
  • Joined: Thu Aug 04, 2011 11:15 am
  • Posts: 6
  • IRC: Rick Wassing
  • Offline
  • Profile
Tags:

More nodes using Anim

Post Posted: Tue Apr 03, 2012 10:34 am
+0-
Hi everyone,

Basically a simple question, but I couldn't find the answer, which could also be simple.

Here it comes: can you set one animation to all elements with a certain style?

Code:
var MyAnim = new Y.Anim({
  node: '.MyClass',
  to: { width: 500 },
  duration:0.5,
  ...etc.
});

Such that when I have 10 elements with class "MyClass", they will all be animated... Now only the first element with that class will have be animated.

Cheers, Rick

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 620
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile

Re: More nodes using Anim

Post Posted: Wed Apr 04, 2012 5:44 am
+0-
Sure. You should use the Transition module. It uses CSS animations whenever it can and it's as simple to use as:
Code:
Y.all('.myClass').transition({ width: '500px', duration: 0.5 })

ispyinternet

  • Joined: Thu Jul 08, 2010 5:28 am
  • Posts: 111
  • Offline
  • Profile

Re: More nodes using Anim

Post Posted: Wed Apr 04, 2012 6:43 am
+0-
would I be able to make the same substitution in my code...

{

_posX : 100,
_posY : 100,

do_animations : function() {

var animate = function(node) {

var

anim = new Y.Anim(
{
node: node,
duration: 0.5,
easing: Y.Easing.elasticOut
});

anim.set('to', { xy: [this._posX, this._posY] });

anim.run();
};

this.get("container").all("li").each(animate,this);
}
}

Im not bothered about the easing, but I want to animate position.

Also can you quickly explain why you can write the code as Y.all(x).transition(...) and if this would be at all possible with Y.Anim and if it is quicker or no different to using each

Thanks

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 620
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile
Tags:

Re: More nodes using Anim

Post Posted: Wed Apr 04, 2012 7:01 am
+0-
Yes, you can replace all of that code with:
Code:
this.get('container')..all('li').transition({
  duration: 0.5,
  easing: 'ease-out',
  left: this._posX + 'px',
  top: this._posY + 'px'
})

You should look at the Transition module docs. Its advantages are: simplicity of the API, works as a method of Node and NodeList (aka Y.all) and it's a lot faster in modern browsers because it uses CSS transitions when posible. When CSS transitions are not available, it uses Y.Anim in the background without having to deal with creating a Y.Anim instance.

In practice, Y.Anim is only useful when you need the fine-grained control over the animation that an Anim instance gives you.

ispyinternet

  • Joined: Thu Jul 08, 2010 5:28 am
  • Posts: 111
  • Offline
  • Profile

Re: More nodes using Anim

Post Posted: Wed Apr 04, 2012 10:27 am
+0-
What if one of the properties that you wanted to pass into transition were related to the actual node the transition method is being applied to? Is there any way to do this? especially in a Y.all scenario?, I was able to do this when using .each() using the context variable 'this'

but....

var that = this;

this.get("container").all("li").transition(
{
duration: 0.5,
easing : 'ease-out',
left : that._oldThumbPosition[NEED TO GET YUID OF NODE HERE].posX,
top : that._oldThumbPosition[NEED TO GET YUID OF NODE HERE].posY});

I am guessing this can't be done?

Thanks

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 620
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile

Re: More nodes using Anim

Post Posted: Wed Apr 04, 2012 12:00 pm
+0-
Yup, you can use NodeList.each().
Code:
// double the width of each node with an animation
Y.all(selector).each(function (node) {
  node.transition({
    width: node.get('offsetWidth') * 2 + 'px'
  });
});
  [ 6 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum