티스토리 뷰

<!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>

출처: gahyun-web-diary.tistory.com/7

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함