[英]Google Pie chart rendered outside of div area when inside a dropdown
[英]Load chart pie inside div when it is in viewpoint
我正在使用easypiechart插件,並且僅當用戶向下滾動到.skills div時,我才希望它加載它。 我正在使用視口插件 。
我已經試過像這樣:
<script src="js/viewport.js"></script>
<script>
(function(){
if ($(".skills:in-viewport")){
jQuery.getScript("js/jquery.easypiechart.min.js").done(function() {
$('.chart').easyPieChart({
easing: 'easeOutBounce',
onStep: function(from, to, percent) {
$(this.el).find('.percent').text(Math.round(percent));
}
});
});
};
});
</script>
處於視點時不顯示。
謝謝!
您可以在沒有視口插件的情況下進行操作。 您可以使用$(window).height()
,當用戶向下滾動時,請檢查您希望圖表所在的div
的距離是否小於滾動距離+ $(window).height()
,如果是,則繪制它。
這是代碼:
var el = document.getElementById('your-div'),
topDistance = el.getBoundingClientRect().top,
drawn = false;
function drawPieChart() {
jQuery.getScript("js/jquery.easypiechart.min.js").done(function() {
$('.chart').easyPieChart({
easing: 'easeOutBounce',
onStep: function(from, to, percent) {
$(this.el).find('.percent').text(Math.round(percent));
}
});
});
}
function handleScroll() {
if (document.body.scrollTop + $(window).height() > topDistance) {
drawn || drawPieChart();
drawn = true;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.