🥸NumScroller, Counter From Zero To Value - Javascript Animation (ok)
https://codepen.io/shivasurya/pen/yyBoJX
Example 0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="numbers">
<div class="container" id="main">
<h6 class="red-title">BY THE NUMBERS</h6>
<h2 class="stats-heading">We’ll always measure up to your expectations</h2>
<div class="numbers-box">
<h1 class="count" max-data="50">30</h1>
<h6>years of experience</h6>
</div>
<div class="numbers-box">
<h1 class="count" max-data="37">0</h1>
<h6>countires supplied</h6>
</div>
<div class="numbers-box">
<h1 class="count" max-data="128">0</h1>
<h6>group automation employees</h6>
</div>
</div>
</section>
<script>
var runAlready;
var counting;
function startCounter(a) {
runAlready = true;
counting = true;
$('.count').each(function () {
var $this = $(this);
$this.text(a);
countTo = $this.attr('max-data');
$({
countNum: $this.text()
}).animate({
countNum: countTo
},
{
duration: 2000,
easing: 'swing',
step: function () {
$this.text(Math.floor(this.countNum));
},
complete: function () {
$this.text(this.countNum);
counting = false;
}
});
})
}
$(window).scroll(function () {
var oTop = $('#main').offset().top;
var a = 0;
if (!runAlready && $(window).scrollTop() > oTop || !counting && $(window).scrollTop() < oTop) {
startCounter(a);
}
});
</script>
</body>
</html>
.counter-box {
display: block;
background: #f6f6f6;
padding: 40px 20px 37px;
text-align: center
}
.counter-box p {
margin: 5px 0 0;
padding: 0;
color: #909090;
font-size: 18px;
font-weight: 500
}
.counter {
display: block;
font-size: 32px;
font-weight: 700;
color: #666;
line-height: 28px
}
.counter-box.colored {
background: #eab736;
}
.counter-box.colored p,
.counter-box.colored .counter {
color: #fff;
}
Example 1
C:\Users\Administrator\Documents\Lorem\index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section id="main" class="main">
<div class="container">
<div class="count-heading">
<div class="count" max-data="10">1</div>
<h2>Project</h2>
</div>
<div class="count-heading">
<div class="count" max-data="20">1</div>
<h2>Project</h2>
</div>
<div class="count-heading">
<div class="count" max-data="30">1</div>
<h2>Project</h2>
</div>
<div class="count-heading">
<div class="count" max-data="40">1</div>
<h2>Project</h2>
</div>
</div>
</section>
<script>
var count = document.getElementsByClassName("count");
var inc = [];
function intervalFunc() {
for (let i = 0; i < count.length; i++) {
inc.push(1);
if (inc[i] != count[i].getAttribute("max-data")) {
inc[i]++;
}
count[i].innerHTML = inc[i];
}
}
var main = document.getElementById("main");
window.onscroll = function () {
var timer = setInterval(() => {
var topElem = main.offsetTop;
var btmElem = main.offsetTop + main.clientHeight;
var topScreen = window.scrollY;
var btmScreen = window.scrollY + window.innerHeight;
// console.log(btmScreen);
if (btmScreen > topElem && topScreen < btmElem) {
intervalFunc();
} else {
clearInterval(timer);
for (let i = 0; i < count.length; i++) {
count[i].innerHTML = 1;
inc = [];
}
}
}, 100);
}
</script>
</body>
</html>
C:\Users\Administrator\Documents\Lorem\style.scss
body {
padding: 0;
margin: 0;
height: 1500px;
}
.main {
background-color: #fff;
padding: 20px 0;
}
.container {
padding: 0 5%;
margin: 0 auto;
display: flex;
}
.count-heading {
flex: 1;
font-size: 40px;
text-align: center;
border: 2px solid red;
background-color: pink;
color: #fff;
}
Example 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="test4.css">
<title>Document</title>
</head>
<body>
<a href="https://www.i-visionblog.com/2022/05/odometerjs-animated-number-counter-from.html" class="linker">New Updated Tutorial: Odometer.js Animated Number Counter From Zero To Value - JavaScript Animation Part 2 - i-visionblog </a>
<div class="shiva">
<div class="shiva__left">
<span class="count">200</span><span class="text">Text</span>
</div>
<div class="shiva__right">
Lorem, ipsum, dolor.
</div>
</div>
<div class="shiva">
<div class="shiva__left">
<span class="count">1000</span><span class="text">Text</span>
</div>
<div class="shiva__right">
Lorem, ipsum, dolor.
</div>
</div>
<div class="shiva">
<div class="shiva__left">
<span class="count">853</span><span class="text">Text</span>
</div>
<div class="shiva__right">
Lorem, ipsum, dolor.
</div>
</div>
<div class="shiva">
<div class="shiva__left">
<span class="count">154</span><span class="text">Text</span>
</div>
<div class="shiva__right">
Lorem, ipsum, dolor.
</div>
</div>
<div class="shiva">
<div class="shiva__left">
<span class="count">10</span><span class="text">Text</span>
</div>
<div class="shiva__right">
Lorem, ipsum, dolor.
</div>
</div>
<div class="shiva">
<div class="shiva__left">
<span class="count">87</span><span class="text">Text</span>
</div>
<div class="shiva__right">
Lorem, ipsum, dolor.
</div>
</div>
<div style="clear:both"></div>
<div id="talkbubble"><span class="count">1421</span></div>
<div id="talkbubble"><span class="count">145</span></div>
<div id="talkbubble"><span class="count">78</span></div>
<br />
<br />
<a class="linker" href="http://www.i-visionblog.com/2014/11/jquery-animated-number-counter-from-zero-to-value-jquery-animation.html" target="_blank">visit Tutorial in Blog</a>
<br />
<script src="//code.jquery.com/jquery-3.7.1.min.js"></script>
<script type="text/javascript">
$('.count').each(function() {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now));
}
});
});
</script>
</body>
</html>
.shiva {
width: 100px;
height: 100px;
background: red;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
float: left;
margin: 5px;
}
.count {
line-height: 100px;
color: white;
margin-left: 30px;
font-size: 25px;
}
#talkbubble {
width: 120px;
height: 80px;
background: white;
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;
width: 0;
height: 0;
border-top: 13px solid transparent;
border-right: 26px solid white;
border-bottom: 13px solid transparent;
}
.linker {
font-size: 20px;
font-color: black;
}
Example 3
PreviousCreating a Countdown Timer, dakhoathienhoa.com.vn (oK)NextClick Button background-hover white (ok)
Last updated