[ 3 posts ]

John Mizliso

  • Username: abxccd
  • Joined: Sun Jan 22, 2012 11:20 pm
  • Posts: 48
  • Offline
  • Profile

Anim animating percentages

Post Posted: Mon Feb 06, 2012 9:44 pm
+0-
I am using Anim to animate certain elements in a document.

I have setted the final positions of the elements in CSS, so that if the user does not have Javascript enabled, he will just see the page without any animations.

I have a div called content that is aligned in the middle of the page using top: 50% and left: 50%.

This way, no matter what happens, when the window is resized, the content div is centered horizontally and vertically.

This is the code I am using:

Code:
YUI().use('anim', function(Y) {
    var anim = new Y.Anim({
        node: '#content',
        from: {
            top: function(node) {
         
                  return Y.one('body').getStyle('height');
              },
            opacity: 0,
        },

        to: {
           top: function(node) {
               Y.log(node.getStyle('top'));
                  return node.getStyle('top');
              },
              opacity: 1,
        },

        duration: 0.8,

        easing: 'backOut',
       
       
    });
        anim.run();

});


The problem is that while the animation works properly, once the animation ends, the "top" property is set to a pixel amount and not 50%. This causes the content div to not be centered vertically when the window is resized.

I have tried setting the final top property to '50%' manually, but the animation does not give the intended effect.

Is there anyway to get the div centered vertically after the animation with only CSS?

John Lindal

YUI Contributor

  • Username: jafl
  • Joined: Mon Nov 02, 2009 2:33 pm
  • Posts: 358
  • Location: Los Angeles, CA
  • Twitter: jafl5272
  • GitHub: jafl
  • Gists: jafl
  • Offline
  • Profile

Re: Anim animating percentages

Post Posted: Mon Feb 13, 2012 8:48 am
+0-
Try subscribing to the "end" event and then setting the value.

John Mizliso

  • Username: abxccd
  • Joined: Sun Jan 22, 2012 11:20 pm
  • Posts: 48
  • Offline
  • Profile

Re: Anim animating percentages

Post Posted: Fri Feb 17, 2012 1:41 am
+0-
Thanks.

That's what I ended up doing :)
  [ 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