Search the web
Sign In
New User? Sign Up
ydn-javascript · Yahoo! User Interface Library Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
YUI - Animation - To & Back   Message List  
Reply | Forward Message #4405 of 52123 |
Re: [ydn-javascript] YUI - Animation - To & Back

hi Dav,

Thanks for sharing you're example.

You can achieve this effect with a single animation instance by changing the "attributes" property.  This will simplify your code considerably.

Something like:
var isExpanded = false;

var attributes = {
    width: { to: 300 },
    height: { to: 300 },
    top: { to: 300 },
    left: { to: 300 }
};

var attributes2 = {
    width: { to: 150 },
    height: { to: 150 },
    top: { to: 150 },
    left: { to: 150 }
};

var myAnim = new YAHOO.util.Anim('test1', attributes);

myAnim.onComplete.subscribe(
   function() {
      isExpanded = !isExpanded;
      this.attributes = (isExpanded) ? attributes2 : attributes;
   }
);

YAHOO.util.Event.addListener('test1', 'click', function() {myAnim.animate()});

Matt

dav.glass@... wrote:
From the Animations onComplete.subscribe function, you could remove the click listener and add the new one...

Here's an example:
http://blog.davglass.com/files/yui/animagain/
 
Dav Glass
dav.glass@...
davglass.com
618.694.3476

+ Windows: n. - The most successful computer virus, ever. +
+ A computer without a Microsoft operating system is like a dog
without bricks tied to its head +
+ A Microsoft Certified Systems Engineer is to computing what a
McDonalds Certified Food Specialist is to fine cuisine +


----- Original Message ----
From: loyalstarlight <additionalvocals@...>
To: ydn-javascript@yahoogroups.com
Sent: Tuesday, August 29, 2006 1:30:56 PM
Subject: [ydn-javascript] YUI - Animation - To & Back

Hi guys,

Very simple newbie question for someone.

In the YUI Library there's an example provided for the Easing
animation which changes the elements width from 10px to 500px:

http://developer. yahoo.com/ yui/examples/ animation/ easing.html

<---
YAHOO.example. init = function() {
var anim = new YAHOO.util.Anim( 'demo', { width: {to: 500} }, 1,
YAHOO.util.Easing. bounceOut) ;
YAHOO.util.Event. on(document, 'click', anim.animate, anim, true);
};

YAHOO.util.Event. onAvailable( 'demo', YAHOO.example. init);
--->

How would I go about making the second click change the elements width
back from 500px to 10px? So essentially you click once to expand it
and click again to return it to it's original state and then you can
click again to expand it...and so on.





Tue Aug 29, 2006 9:18 pm

matt.sweeney
Offline Offline
Send Email Send Email

Forward
Message #4405 of 52123 |
Expand Messages Author Sort by Date

Hi guys, Very simple newbie question for someone. In the YUI Library there's an example provided for the Easing animation which changes the elements width from...
loyalstarlight
Offline Send Email
Aug 29, 2006
8:31 pm

From the Animations onComplete.subscribe function, you could remove the click listener and add the new one... Here's an example: ...
dav.glass@...
dav.glass
Offline Send Email
Aug 29, 2006
8:54 pm

hi Dav, Thanks for sharing you're example. You can achieve this effect with a single animation instance by changing the "attributes" property. This will...
Matt Sweeney
matt.sweeney
Offline Send Email
Aug 29, 2006
9:27 pm

Matt -- Good call, I hadn't thought of that 8-) Thanks for the heads up.. Dav Glass dav.glass@... davglass.com 618.694.3476 + Windows: n. - The most...
dav.glass@...
dav.glass
Offline Send Email
Aug 29, 2006
11:18 pm

Matt-- I updated my example to reflect your advise.. Thanks again.. http://blog.davglass.com/files/yui/animagain/ Dav Glass dav.glass@... davglass.com ...
dav.glass@...
dav.glass
Offline Send Email
Aug 30, 2006
12:13 am

Or you could use the YAHOO.ext (Yahoo! UI extensions) library and it could be this code: var test1 = YAHOO.ext.Element.get('test1'); test1.addListener('click',...
Jack Slocum
jack.slocum
Offline Send Email
Aug 30, 2006
10:06 am

Hi Jack, That looks good, but doesn't accomplish Dav's task, which changes other attributes beyond width. The task you demonstrate can be easily accomplished...
Matt Sweeney
matt.sweeney
Offline Send Email
Aug 30, 2006
5:50 pm

Sorry, I didn't see Dave's example. For Dave's task it's almost identical: var test1 = getEl('test1'); test1.on('click', function(){ test1.getWidth >= 300 ? ...
Jack Slocum
jack.slocum
Offline Send Email
Aug 30, 2006
6:42 pm

I'm sure your stuff works as advertised, but the message here is that it is a simple process to modify an Anim's attributes (and other properties) at runtime...
Matt Sweeney
matt.sweeney
Offline Send Email
Aug 30, 2006
10:17 pm

... I agree 100%. But when I look at this: var test1 = new YAHOO.util.Anim('test1', { width: { to: 150 }, height: { to: 150 }, top: { to: 150 }, left: { to:...
Jack Slocum
jack.slocum
Offline Send Email
Aug 30, 2006
11:44 pm

Hey Jack, ... Ahh yes, good point. I forgot to unsubscribe the callback. Should do something more like: var test1 = new YAHOO.util.Anim('test1', { width: {...
Matt Sweeney
matt.sweeney
Offline Send Email
Aug 31, 2006
12:34 am

Hi, All you need to do is keep track of whether it is exanded, and adjust the target width accordingly. This can be done when the animation completes by...
Matt Sweeney
matt.sweeney
Offline Send Email
Aug 29, 2006
9:04 pm

Hi Matt and Dav, Thanks very much for helping me out. Matt, In your example, is there a way of refining the click function to a single element (eg. a link with...
loyalstarlight
Offline Send Email
Aug 29, 2006
10:46 pm

The listener is being added to the "page" or document. If you want to add it to the link called demolink, then the code would look like this: YAHOO.util.Event....
dav.glass@...
dav.glass
Offline Send Email
Aug 29, 2006
11:14 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help