Check once a function is complete

后端 未结 2 1629
离开以前
离开以前 2021-01-23 19:42

I have a lit of offsets for a div that I load when a link is clicked to give a comic book style effect. Each offset activates other animations to give a more dynamic feel.

相关标签:
2条回答
  • 2021-01-23 20:03

    It seems that the core of your problem is the flow of the javascript code. You will want to use a callback function. If you add a callback variable to a function, you can execute code after the function has run its course:

    function foo(callback) {
        // some code you want to execute
    
        // then run the callback function
        if (typeof(callback) == "function")
            callback();
    }
    
    function bar() {
       // some code you want to execute after foo is finished
    }
    

    Now you can run bar() after foo is complete like this:

    foo(bar);
    
    0 讨论(0)
  • 2021-01-23 20:05

    If you utiilise the .data('obj',{currentPosition:index}); approach, you can create a .data() object on an element and have your animations query it to see 'where' they are from 0 to however many items you need in your comic book sequence. Base your animations on the index from 0=>however many and then update the currentPosition when your animation is finished using the callback parameter in the animation.

    Would that direction help? If you can give some example code (simple or otherwise) we might be able to see a way to tie it in?

    0 讨论(0)
提交回复
热议问题