亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使 jquery 計數器與來自 innerHTML 的數據一起工作

如何使 jquery 計數器與來自 innerHTML 的數據一起工作

米琪卡哇伊 2021-08-26 17:00:53
我正在嘗試使用 jquery 制作一個計數器。當數據div直接傳遞到 中時,此計數器起作用,但在將此數據動態附加到divusing.innerHTML調用時不起作用。下面我將計數器代碼應用于.count類的所有元素,并且我希望這個計數器div使用 id = "users" 使用document.getElementById('users').innerHTML = 300;這不起作用。但以下工作: <div id="users" class="count">300</div>$('.count').each(function () {        $(this).prop('Counter',0).animate({            Counter: $(this).text()        }, {            duration: 5000,            easing: 'swing',            step: function (now) {                $(this).text(Math.ceil(now));            }        });     });<div id="users" class="count"></div>document.getElementById('users').innerHTML = 300; 我在使用時得到的輸出document.getElementById('users').innerHTML = 300;是 0,但這是出乎意料的。我有幾個類的元素count依賴于這個計數器。對此的任何幫助將不勝感激。
查看完整描述

3 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

@Ben you need to set the innerHTML before you call the counter animation 

document.getElementById('users').innerHTML = 300;


$('.count').each(function () {

        $(this).prop('Counter',0).animate({

            Counter: $(this).text()

        }, {

            duration: 5000,

            easing: 'swing',

            step: function (now) {

                $(this).text(Math.ceil(now));

            }

        });

     });


查看完整回答
反對 回復 2021-08-26
  • 3 回答
  • 0 關注
  • 232 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號