gpt4 book ai didi

javascript - 如何降低此 jquery 计数器动画的速度

转载 作者:行者123 更新时间:2023-11-28 15:52:31 25 4
gpt4 key购买 nike

我有一个计数器,它会在达到特定百分比时进行动画处理。但是动画速度有点快,我想降低。

下面是我的代码。

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 Fiddle link

我尝试了下面的代码来降低我的 JS 文件的速度,但它没有用。

animateElements();
$(window).scroll(animateElements).animate(slow, 5000);

最佳答案

您可以将持续时间参数添加到 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
}
})

关于javascript - 如何降低此 jquery 计数器动画的速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51423377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com