0👍
Try this way:
var vis=0;
$( document ).scroll(function() {
if(isScrolledIntoView(document.getElementById('your-element'))){
if(vis==0){
//your code
vis=1;
}
}
});
function isScrolledIntoView(el) {
var rect = el.getBoundingClientRect();
var elemTop = rect.top;
var elemBottom = rect.bottom;
var isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight);
return isVisible;
}
- Chartjs-Chart.js charts not rendering data until I inspect element, is it because of async?
- Chartjs-Chartjs annotation plugin colored box colors get summed after switching back and forth
Source:stackexchange.com