Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    function complete event?

    Is there a way to listen for a function to complete? I have a page that has a small animation that plays when certain links are clicked. Everytime the animation completes I need to call a different function that is specific to whatever link was clicked. So it's like I need my animation function to throw a completed event that I can listen for. So for example I'd want to do something like...

    <a href="javascript:OnAnimationComplete(FunctionToCall);StartAnimation()">start</a>

    OnAnimationComplete would set a listener for that complete event and then call the FunctionToCall function when it received the event. Thanks.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,027
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Not sure if this meets your needs:-

    (Function A is startAnimation(), Functions B and C are the functions to run after A)

    Code:
    <a href= "javascript:A(); B()">Link to A and B</a><br>
    <a href= "javascript:A(); C()">Link to A and C</a><br>
    
    <script type = "text/javascript">
    var num = 0;
    function A() {
    for (var i = 1; i<=3; i++) {
    alert ("Here is function A Loop  " + i);
    }
    }
    
    function B() {
    alert ("Function B runs after A has finished")
    }
    
    function C() {
    alert ("Function C runs after A has finished")
    }
    
    </script>
    See also:-

    detecting animations



    Quizmaster: In Roman Catholicism, baptism, confirmation and matrimony are three of the seven what?
    Contestant: Deadly sins.
    Last edited by Philip M; 09-10-2008 at 07:17 PM.

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts
    In my case it's a simple example but in reality of what is going on in my page it isn't done as easily as what I illustrated. The actual animation is a class that instantiates and adds a div to the bottom of the page. During it's creation it also goes through the page and any link that has a rel="shadow" applied to it, it wires up a click handler to start it's own animation. So, I'm not necessarily starting the animation like

    Code:
    <a href="javascript:startanimation">start</a>
    but instead it looks like

    Code:
    <a href="#" rel="shadow">start</a>
    So what I'd like to do is put something in that animation function that is contained in the class that fires an event that my link can listen for. So it would actually look like

    Code:
    <a href="javascript:SetUpListener(FunctionToCallA);" rel="shadow">start a</a>
    <a href="javascript:SetUpListener(FunctionToCallB);" rel="shadow">start b</a>

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    you could add a property to you rclass that the function changes right before the return.

    since events are functions, you can also simply call or return the event invocation to chain it.

    eg:
    Code:
    function animate(){
      //do stuff here
      return animationDone()
    }
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    you could add a property to you rclass that the function changes right before the return.

    since events are functions, you can also simply call or return the event invocation to chain it.

    eg:
    Code:
    function animate(){
      //do stuff here
      return animationDone()
    }
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,027
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Quote Originally Posted by rnd me View Post
    you could add a property to you rclass that the function changes right before the return.

    since events are functions, you can also simply call or return the event invocation to chain it.

    eg:
    Code:
    function animate(){
      //do stuff here
      return animationDone()
    }

    Yes, but the OP wants to call a different function after animate() depending on which link was clicked.

  • Users who have thanked Philip M for this post:

    tyler jones (09-11-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •