티스토리 뷰
<!DOCTYPE HTML>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>숫자가 0부터 점점 커지는 애니메이션</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
* { margin:0; padding:0; box-sizing: border-box;}
.memberCountCon {
position: absolute;
left: 50%;
top: 50%;
font-size: 42px;
transform:translate(-50%, -50%);
}
</style>
</head>
<body id="root">
<div class="memberCountCon"></div>
<script>
var memberCountConTxt= 296842;
$({ val : 0 }).animate({ val : memberCountConTxt }, {
duration: 2000,
step: function() {
var num = numberWithCommas(Math.floor(this.val));
$(".memberCountCon").text(num);
},
complete: function() {
var num = numberWithCommas(Math.floor(this.val));
$(".memberCountCon").text(num);
}
});
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
</script>
</body>
</html>
'JavaScript > 제이쿼리' 카테고리의 다른 글
글자 위로 거품이 올라오는 소스 (0) | 2021.01.06 |
---|---|
사이트 만들때 사용하는 JS 소스 모음 (0) | 2021.01.05 |
메뉴를 따라다니는 메뉴 바 만들기 (0) | 2020.12.10 |
[던파] 눈내리는 소스 (0) | 2020.11.04 |
현재 메뉴 활성화 (0) | 2020.10.28 |