我有一个计数器,可以在达到特定百分比时进行动画处理。但是动画速度有点快,我想降低速度。
下面是我的代码。
HTML
<div class="progressbar" data-animate="false">
<div class="circle" data-percent="90">
<div></div>
</div>
</div>
CSS:
.progressbar {
display: inline-block;
width: 100px;
margin: 25px;
}
.circle {
width: 180px;
height: 180px;
margin: 0 auto;
margin-top: 10px;
display: inline-block;
position: relative;
text-align: center;
}
.circle:after {
width: 120px;
height: 120px;
content: "";
border: 2px solid #fb4f14;
border-radius: 50%;
display: block;
position: absolute;
top: 30px;
left: 30px;
}
.circle canvas {
vertical-align: middle;
border: 2px solid #fb4f14;
border-radius: 50%;
}
.circle div {
position: absolute;
top: 50%;
left: 50%;
margin: -20px 0 0 -86px;
width: 100%;
text-align: center;
line-height: 40px;
font-size: 31px;
}
.circle strong i {
font-style: normal;
font-size: 0.6em;
font-weight: normal;
}
.circle span {
display: block;
color: white;
margin-top: 12px;
}
JS:
$(document).ready(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', true);
$(this).find('.circle').circleProgress({
startAngle: -Math.PI / 2,
value: percent / 100,
size: 180,
thickness: 30,
emptyFill: "rgba(0,0,0, .2)",
fill: {
color: '#fb4f14'
}
}).on('circle-animation-progress', function (event, progress, stepValue) {
$(this).find('div').text((stepValue*100).toFixed(1) + "%");
}).stop();
}
});
}
animateElements();
$(window).scroll(animateElements);
});
部署:
我尝试使用下面的代码来降低我的JS文件的速度,但这没有用。
animateElements();
$(window).scroll(animateElements).animate(slow, 5000);
答案 0 :(得分:3)
您可以将duration参数添加到circleProgress:
circleProgress({
startAngle: -Math.PI / 2,
value: percent / 100,
size: 180,
thickness: 30,
emptyFill: "rgba(0,0,0, .2)",
fill: {
color: '#fb4f14'
},
animation: {
duration: 3000
}
})
答案 1 :(得分:1)
答案 2 :(得分:1)
您需要在js代码内添加一个属性(动画:{duration:3000})
$(this).find('.circle').circleProgress({
startAngle: -Math.PI / 2,
value: percent / 100,
size: 180,
thickness: 30,
animation:{duration: 3000},
emptyFill: "rgba(0,0,0, .2)",
fill: {
color: '#fb4f14'
}
有关圆形动画的更多信息,您可以访问https://github.com/kottenator/jquery-circle-progress