【发布时间】:2015-11-22 02:24:54
【问题描述】:
问题: 我正在为一个项目使用 Circle Progress JQuery 插件(版本:0.6.0)并对其进行了一些修改,但是,每个圆圈似乎在很长一段时间内重复自身(或循环),而不仅仅是执行动画一次。
由于所做的修改,例如添加一个链接,如果单击它,动画开始的位置,似乎不是问题所在。当您开始向下滚动时,当您这样做时 - 每个圆圈都会根据设置的百分比开始动画,但会在停止之前不断重复几次。当用户向下滚动时,它应该只为每个圆圈启动一次动画,但我似乎无法弄清楚为什么会发生这种情况。
这是我所拥有的:
$('.about_nav a:nth-of-type(2)').click(function () {
function animateElements() {
$('.progressbar').each(function () {
var elementPos = $(this).offset().top;
var topOfWindow = $(window).scrollTop();
var percent = $(this).find('.circle').attr('data-percent');
var percentage = parseInt(percent, 10) / parseInt(100, 10);
var animate = $(this).data('animate');
if (elementPos < topOfWindow + $(window).height() - 30 && !animate) {
$(this).data('animate', false); // Change this 'false -or- true' - Currently set to false so that each time a user clicks on 'Skill-set' link, animation occurs
$(this).find('.circle').circleProgress({
startAngle: -Math.PI / 2,
value: percent / 100,
thickness: 2, // Change this for thickness
fill: {
color: '#16A085'
}
}).on('circle-animation-progress', function (event, progress, stepValue) {
$(this).find('.percent').text((stepValue*100).toFixed(0) + "%"); // NOTE: Change '.toFixed(0)' to '.toFixed(1)' to get 1 decimal place to the right...
}).stop();
}
});
}
animateElements();
$('.about_body_wrapper').scroll(animateElements);
});
这是我的意思的粗略演示:DEMO - 单击“技能集”选项卡并向下滚动。
对此的任何帮助将不胜感激!
【问题讨论】:
标签: javascript jquery