I have a chart made in CSS and HTML, in this chart there is an animation for the chart loading. I want to start this animation only when I scroll on the view of the div that contain the chart.
I want to charge the chart only when I'm on it on the page, I know that I have to use javascript but I'm a very beginner in JS so I don't know if it is possible to do something like that.
This is the fiddle of the chart:
https://jsfiddle.net/matteous1/pdL0kbqk/
HTML
<ul class="chart">
<li>
<span style="height:5%; background: rgba(0, 102, 255, 0.80);" title="ActionScript"></span>
</li>
<li>
<span style="height:70%; background: rgba(204, 51, 51, 0.80);" title="JavaScript"></span>
</li>
<li>
<span style="height:50%; background: rgba(255, 186, 2, 0.80);" title="CoffeScript"></span>
</li>
<li>
<span style="height:75%; background: rgba(0, 153, 102, 0.80);" title="HTML"></span>
</li>
<li>
<span style="height:90%; background: rgba(0, 102, 255, 0.80);" title="HTML"></span>
</li>
<li>
<span style="height:15%; background: rgba(204, 51, 51, 0.80);" title="HTML"></span>
</li>
<li>
<span style="height:40%; background: rgba(255, 186, 2, 0.80);" title="HTML"></span>
</li>
<li>
<span style="height:55%; background: rgba(0, 153, 102, 0.80);" title="HTML"></span>
</li>
</ul>
CSS
.chart {
display: table;
table-layout: fixed;
width: 90%;
/*max-width: 700px;*/
height: 65%;
margin: 0 auto;
background-image: linear-gradient(to top, rgba(0, 0, 0, 0.1) 2%, rgba(0, 0, 0, 0) 2%);
background-size: 100% 50px;
background-position: left top;
}
.chart li {
position: relative;
display: table-cell;
vertical-align: bottom;
height: 200px;
}
.chart span {
margin: 0 1em;
display: block;
/*background: rgba(209, 236, 250, 0.75);*/
animation: draw 1s ease-in-out;
}
.chart span:before {
position: absolute;
left: 0;
right: 0;
top: 100%;
padding: 5px 1em 0;
display: block;
text-align: center;
content: attr(title);
word-wrap: break-word;
}
@keyframes draw {
0% {
height: 0;
}
}