###はじめに
お読み下さりありがとうございます。
こちらの記事を参考にjQueryを使用してChart.jsを使用しているのですが、
スクロール位置がChart.jsを使用している要素に来たときにアニメーションをさせる、というやり方がわからず
今回ご質問させていただきました。
JavaScriptならびにjQueryはあまり得意ではないのですが、何卒ご教授頂けますと幸いです。
なお、下記のコードは実際のコードから必要部分のみの抜粋したものとなっております。
###該当のソースコード
html
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="UTF-8"> 5 <style> 6 #wrapper{width:100%} 7 #chart{list-style:none;display:flex} 8 .item{width:calc(100% / 4)} 9 </style> 10</head> 11<body> 12 <div id="wrapper"> 13 <ul id="chart"> 14 <li class="item"> 15 <canvas id="chart1" width="220" height="180"></canvas> 16 </li> 17 <li class="item"> 18 <canvas id="chart2" width="220" height="180"></canvas> 19 </li> 20 <li class="item"> 21 <canvas id="chart3" width="220" height="180"></canvas> 22 </li> 23 <li class="item"> 24 <canvas id="chart4" width="220" height="180"></canvas> 25 </li> 26 </ul> 27 </div> 28 29 30 <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> 31 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.min.js"></script> 32 <script> 33 $(function (){ 34 const config = { 35 type: 'bar', 36 data: barChartData, 37 responsive : false, 38 options: { 39 legend: {display: false}, 40 tooltips: {enabled: false}, 41 } 42 } 43 const context = $("#chart1") 44 const chart = new Chart(context,config) 45 }) 46 const barChartData = { 47 labels : ["1","2","3","4","5"], 48 datasets : [ 49 { 50 backgroundColor: "#b3a", 51 data : [10,55,30,70,10] 52 } 53 ] 54 } 55 56 $(function (){ 57 const config = { 58 type: 'bar', 59 data: barChartData2, 60 responsive : false, 61 options: { 62 legend: {display: false}, 63 tooltips: {enabled: false} 64 } 65 } 66 const context = $("#chart2") 67 const chart = new Chart(context,config) 68 }) 69 const barChartData2 = { 70 labels : ["1","2","3","4","5"], 71 datasets : [ 72 { 73 backgroundColor: "#dec", 74 data : [10,50,40,60,20] 75 } 76 ] 77 } 78 79 $(function (){ 80 const config = { 81 type: 'doughnut', 82 data: barChartData3, 83 responsive: false, 84 options: { 85 legend: {display: false}, 86 tooltips: {enabled: false} 87 } 88 } 89 const context = $("#chart3") 90 const chart = new Chart(context,config) 91 }) 92 const barChartData3 = { 93 labels : ["1","2"], 94 datasets : [ 95 { 96 backgroundColor: ["#fbd","#aaa"], 97 data : [10,90] 98 } 99 ] 100 } 101 102 $(function (){ 103 const config = { 104 type: 'pie', 105 data: barChartData4, 106 responsive : false, 107 options: { 108 legend: {display: false}, 109 tooltips: {enabled: false} 110 } 111 } 112 const context = $("#chart4") 113 const chart = new Chart(context,config) 114 }) 115 const barChartData4 = { 116 labels : ["1","2"], 117 datasets : [ 118 { 119 backgroundColor: ["#2ae","#cea"], 120 data : [45,55] 121 } 122 ] 123 } 124 </script> 125</body> 126</html>
###試したこと
既に投稿されているこちらの記事も参考にしてみたのですが、
書き方が違うためどう取り入れれば良いのかわからなくなってしまいました。
###補足情報(言語/FW/ツール等のバージョンなど)
確認環境はMac OSX El Capitan/Google Chrome62.0.3202.94です。
以上、何卒宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/27 08:06