[ 3 posts ]

Carlos Adriano Portes

  • Username: xcap2000
  • Joined: Mon Feb 14, 2011 2:09 pm
  • Posts: 8
  • Location: Brazil
  • GitHub: xcap2000
  • Gists: xcap2000
  • IRC: xcap2000
  • Offline
  • Profile
Tags:

Cloning

Post Posted: Wed May 04, 2011 3:41 pm
+0-
Hi,

I have been studying YUI 3 for about 3 months and now I am playing with some of its componentes, I would like to know whats wrong with the code below:

Code:
YUI({ filter: 'raw' }).use('anim', function (Y)
         {
            Y.on('domready', function ()
            {
               //--------------------------------------------------------------------------------------------------//

               var animBackBoth = new Y.Anim
               ({
                  node: '#backBoth',
                  easing: Y.Easing.backBoth,
                  from:
                  {
                     height: 25,
                     width: 100
                  },
                  to:
                  {
                     height: 25,
                     width: 200
                  },
                  duration: 1.5
               });

               //--------------------------------------------------------------------------------------------------//

               var animBackIn = Y.clone(animBackBoth);
               animBackIn.set('node', '#backIn');
               animBackIn.set('easing', Y.Easing.backIn);

               //--------------------------------------------------------------------------------------------------//

               Y.on('click', function () { animBackBoth.run(); }, '#backBoth');
               Y.on('click', function () { animBackIn.run(); }, '#backIn');

            });
         });

My intent was to create just one instance of Anim and clone it just modifying what I wanted, from what I read from the documentation I thought I was in the right path using a deep cloning process, but when I click on '#backBoth' div what animates is '#backIn'.

I would be happy if someone help me with it.

Thanks in advance.

Carlos Adriano Portes

Juan Ignacio Dopazo

YUI Contributor

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

Re: Cloning

Post Posted: Thu May 05, 2011 3:46 pm
+0-
I don't know about "wrong", but I usually try to avoid cloning objects exactly because of these cases.

Have you tried doing something like this?

Code:
var animBackIn = new Y.Anim(animBackBoth.getAttrs());

Carlos Adriano Portes

  • Username: xcap2000
  • Joined: Mon Feb 14, 2011 2:09 pm
  • Posts: 8
  • Location: Brazil
  • GitHub: xcap2000
  • Gists: xcap2000
  • IRC: xcap2000
  • Offline
  • Profile
Tags:

Re: Cloning

Post Posted: Sat May 07, 2011 5:22 pm
+0-
jdopazo,

First of all thank you for answering, the way you showed does work and I was not aware of the way of copying attributes, by wrong I mean that the object that was cloned get its node and easing attributes changed during the clone process, I have filled a bug in order to check it out.

Thank you very much.
  [ 3 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