Chartist.js动画结束事件

时间:2018-06-19 17:49:17

标签: javascript chartist.js

我想在图表准备好后显示一个块。我没有在docs中找到“动画结束”事件。所有动画制作完成后,是否可以执行一些代码?

2 个答案:

答案 0 :(得分:0)

我相信您可以使用“创建的”事件处理程序。

var chart = new Chartist.Line(...);
// attach an event handler to the "created" event of the chart:
chart.on("created", function () {
    // call some function
    triggerSomeEvent();
});

Src:Chartist.js and events

答案 1 :(得分:0)

感谢Mark的帮助。我对问题的解决:

var chart = new Chartist.Line(...);

var endOfAnimation;
var seq = 0;
var delays = 48;
var durations = 300;

chart.on("draw", function(data) {
    seq++;

    /* Animations */

    /* element.animate({ 
           opacity: {
           begin: seq * delays,
           dur: durations,
           from: 0,
           to: 1
       }); */
}

chart.on("created", function() {
    clearTimeout(endOfAnimation); // prevent function call duplication 

    endOfAnimation = setTimeout( function(){

        /* some code after all animations are finished */ 

    }, (seq + 1) * delays + durations);

    seq = 0;
    });