<bdo id='MZRbk'></bdo><ul id='MZRbk'></ul>
    <i id='MZRbk'><tr id='MZRbk'><dt id='MZRbk'><q id='MZRbk'><span id='MZRbk'><b id='MZRbk'><form id='MZRbk'><ins id='MZRbk'></ins><ul id='MZRbk'></ul><sub id='MZRbk'></sub></form><legend id='MZRbk'></legend><bdo id='MZRbk'><pre id='MZRbk'><center id='MZRbk'></center></pre></bdo></b><th id='MZRbk'></th></span></q></dt></tr></i><div id='MZRbk'><tfoot id='MZRbk'></tfoot><dl id='MZRbk'><fieldset id='MZRbk'></fieldset></dl></div>
  1. <legend id='MZRbk'><style id='MZRbk'><dir id='MZRbk'><q id='MZRbk'></q></dir></style></legend>

    <small id='MZRbk'></small><noframes id='MZRbk'>

      <tfoot id='MZRbk'></tfoot>
    1. 滚动到该部分时如何使 Chart.js 动画?

      How to make the Chart.js animate when scrolled to that section?(滚动到该部分时如何使 Chart.js 动画?)
      <tfoot id='B2uKH'></tfoot>
      1. <i id='B2uKH'><tr id='B2uKH'><dt id='B2uKH'><q id='B2uKH'><span id='B2uKH'><b id='B2uKH'><form id='B2uKH'><ins id='B2uKH'></ins><ul id='B2uKH'></ul><sub id='B2uKH'></sub></form><legend id='B2uKH'></legend><bdo id='B2uKH'><pre id='B2uKH'><center id='B2uKH'></center></pre></bdo></b><th id='B2uKH'></th></span></q></dt></tr></i><div id='B2uKH'><tfoot id='B2uKH'></tfoot><dl id='B2uKH'><fieldset id='B2uKH'></fieldset></dl></div>

          <small id='B2uKH'></small><noframes id='B2uKH'>

              <tbody id='B2uKH'></tbody>

            • <bdo id='B2uKH'></bdo><ul id='B2uKH'></ul>

                <legend id='B2uKH'><style id='B2uKH'><dir id='B2uKH'><q id='B2uKH'></q></dir></style></legend>

                本文介绍了滚动到该部分时如何使 Chart.js 动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 Chart.js 中的饼图 (http://www.chartjs.org/docs/#pieChart-exampleUsage).一切都很顺利,但动画会在页面加载后立即发生,但由于用户必须向下滚动才能看到图表,所以他们不会看到动画.无论如何我可以让动画只有在滚动到那个位置时才开始?另外,如果可能的话,是否可以在每次看到该图表时制作动画?

                I am trying to use the pie chart from Chart.js (http://www.chartjs.org/docs/#pieChart-exampleUsage). Everything works smooth, but the animation happens as soon as the page loads, but since the user has to scroll down to see the chart, they won't see the animation. Is there anyway I can make the animation to start only when scrolled to that position? Also if possible, is it possible to animate everytime when that chart becomes into view?

                我的代码如下:

                <canvas id="canvas" height="450" width="450"></canvas>
                    <script>
                        var pieData = [
                                {
                                    value: 30,
                                    color:"#F38630"
                                },
                                {
                                    value : 50,
                                    color : "#E0E4CC"
                                },
                                {
                                    value : 100,
                                    color : "#69D2E7"
                                }
                
                            ];
                
                    var myPie = new Chart(document.getElementById("canvas").getContext("2d")).Pie(pieData);
                
                    </script>
                

                推荐答案

                您可以将检查某物是否可见与一个标志结合起来,以跟踪图形是否在出现在视口中后被绘制(尽管这样做使用插件 bitiou 发布会更简单):

                You can combine the check for whether something is viewable with a flag to keep track of whether the graph has been drawn since it appeared in the viewport (though doing this with the plugin bitiou posted would be simpler):

                http://jsfiddle.net/TSmDV/

                var inView = false;
                
                function isScrolledIntoView(elem)
                {
                    var docViewTop = $(window).scrollTop();
                    var docViewBottom = docViewTop + $(window).height();
                
                    var elemTop = $(elem).offset().top;
                    var elemBottom = elemTop + $(elem).height();
                
                    return ((elemTop <= docViewBottom) && (elemBottom >= docViewTop));
                }
                
                $(window).scroll(function() {
                    if (isScrolledIntoView('#canvas')) {
                        if (inView) { return; }
                        inView = true;
                        new Chart(document.getElementById("canvas").getContext("2d")).Pie(data);
                    } else {
                        inView = false;  
                    }
                });
                

                这篇关于滚动到该部分时如何使 Chart.js 动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                  <tbody id='rECaT'></tbody>

                • <bdo id='rECaT'></bdo><ul id='rECaT'></ul>
                • <small id='rECaT'></small><noframes id='rECaT'>

                    <i id='rECaT'><tr id='rECaT'><dt id='rECaT'><q id='rECaT'><span id='rECaT'><b id='rECaT'><form id='rECaT'><ins id='rECaT'></ins><ul id='rECaT'></ul><sub id='rECaT'></sub></form><legend id='rECaT'></legend><bdo id='rECaT'><pre id='rECaT'><center id='rECaT'></center></pre></bdo></b><th id='rECaT'></th></span></q></dt></tr></i><div id='rECaT'><tfoot id='rECaT'></tfoot><dl id='rECaT'><fieldset id='rECaT'></fieldset></dl></div>
                          <legend id='rECaT'><style id='rECaT'><dir id='rECaT'><q id='rECaT'></q></dir></style></legend>
                        1. <tfoot id='rECaT'></tfoot>