我有一个计数器,计数1-20。问题是每当页面加载/刷新时就开始计数。所以观看者看不到动画计数。当访问者到达特定部分时,我如何开始计数(部分ID =计数器)。在特定html部分开始活动
HTML
<section id=counter>
<div id="talkbubble""><span class="count">20</span></div>
</section>
CSS
.count
{line-height: 100px;color:white;margin-left:30px;font-size:25px;}
#talkbubble {width: 120px;height:80px;background: red;position: relative; -moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px; float:left; margin:20px;}
#talkbubble:before {content:"";position: absolute;right: 100%;top: 26px; idth: 0;height: 0;border-top: 13px solid transparent;border-right: 26px solid red;border-bottom: 13px solid transparent;}
jQuery的
$('.count').each(function() {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
谢谢,这正是我一直想要的。 –