我有一個計數器,計數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));
}
});
});
謝謝,這正是我一直想要的。 –