hi mọi người, mình đang muốn tạo 1 cái function Animation số điếm nó tự tăng khi được load lên. VD: mình muốn số tự động tăng từ 10 đến 100 khi nó load chạy cho người dùng thấy số cho đẹp ý. Sử dụng javascript cảm ơn mọi người.
Đây bạn nhé, đoạn code javascript mình cũng hay xài: HTML: function animateValue(obj, start, end, duration) { //số thứ tự chạy tăng hoặc chạy giảm let startTimestamp = null; const step = (timestamp) => { if (!startTimestamp) startTimestamp = timestamp; const progress = Math.min((timestamp - startTimestamp) / duration, 1); obj.innerHTML = Math.floor(progress * (end - start) + start).toLocaleString('en-US').replace(',','.'); if (progress < 1) { window.requestAnimationFrame(step); } }; window.requestAnimationFrame(step); } try{ const obj_value = document.getElementById('valueadd'); animateValue(obj_value, 0, 1000, 5000); } catch (err) { }