Jump to content
Search Community

Sopstance

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by Sopstance

  1. Hi, 

    I have a button in the iframe where it will trigger the some animation at the parent window, but im not sure why its not responding to clicked. 

     

    <div id="redSlideAuto" onclick="parent.autoIn(redSlide);"></div>

    <div id="blueSlideAuto" onclick="parent.autoIn(blueSlide);"></div>

     

     

    On 5/27/2016 at 11:29 PM, Carl said:

    Hi and welcome to the GreenSock forums,

     

    Great question and thanks for the demo.

     

    I had something similar sitting around so I edited it to hopefully match your needs.

     

    the basic idea is that you keep track of a currentAnimation timeline. When you request a new "slide" reverse() the currentAnimation and also give it an onReverseComplete callback that will trigger the next animation. There are more object-oriented ways of setting this up, but I think this a more basic / straight-forward way to illustrate it.

     

    var red = new TimelineLite({}); //plays automatically on load
    red.staggerTo("#redSlide .box", 1, {x:300}, 0.3);
    
    var blue = new TimelineLite({paused:true});
    blue.staggerTo("#blueSlide .box", 1, {x:-300}, 0.3);
    
    var currentAnimation = red;
    var nextAnimation;
    
    function animateIn(animation) {
        //only do stuff if requested animation is different than active slide
        if(animation != currentAnimation) {
          currentAnimation.reverse().timeScale(3);//faster speed
          currentAnimation.eventCallback("onReverseComplete", playNext)
          nextAnimation = animation;
        }
    }
    
    function playNext(){
      nextAnimation.play().timeScale(1);
      currentAnimation = nextAnimation; 
    }
    
    
    $("#redSlideIn").click(function() {
      animateIn(red);
      
    })
    
    $("#blueSlideIn").click(function() {
      animateIn(blue);
    })

    demo: 

    See the Pen yJLyxM?editors=0010 by GreenSock (@GreenSock) on CodePen

     

    its a little easier if you don't have to wait for one to reverse before playing the other, but I think this is what you wanted.

     

  2. Hi,

     

    I am creating a single page website with different sections button. Each section will contain their own set of animation.

     

    By default when user first visit the webpage it will load the set A animation.

    Let say if I am on set A section and I click on set C button, it should reverse the set A animation (onCompleteReverse) and play set B animation. Can anyone guide me how to do it? 

     

    Thanks!

     

     

     

    See the Pen rLBXNM by Sopstance (@Sopstance) on CodePen

×
×
  • Create New...