250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 풀스택
- react
- 애니메이션
- php
- HTML
- javascript
- IOS
- front-end
- hover
- 개발자
- iOS 개발자
- 비전공자
- effect
- image
- xcode
- 비전공 개발자
- button
- html5
- jQuery
- keyframes
- 프론트엔드
- SWIFT
- MAC
- iPhone
- ipad
- 자바스크립트
- Animation
- css3
- 백엔드
- CSS
Archives
- Today
- Total
비전공자 개발일기
Javascript - Incrementing Counter 본문
728x90
SMALL
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Incrementing Counter</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin="anonymous" />
<link rel="stylesheet" href="style.css">
<script defer src="main.js"></script>
</head>
<body>
<div class="counter-container">
<i class="fab fa-twitter fa-3x"></i>
<div class="counter" data-target="12000"></div>
<span>Twitter Followers</span>
</div>
<div class="counter-container">
<i class="fab fa-youtube fa-3x"></i>
<div class="counter" data-target="5000"></div>
<span>YouTube Subscribers</span>
</div>
<div class="counter-container">
<i class="fab fa-facebook fa-3x"></i>
<div class="counter" data-target="7500"></div>
<span>Facebook Fans</span>
</div>
</body>
</html>
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap');
* {
box-sizing: border-box;
}
body {
background-color: #8e44ad;
color: #fff;
font-family: 'Roboto Mono', sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
margin: 0;
}
.counter-container {
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
margin: 30px 50px;
}
.counter {
font-size: 60px;
margin-top: 10px;
}
@media(max-width: 580px) {
body {
flex-direction: column;
}
}
const counters = document.querySelectorAll(".counter");
counters.forEach(counter => {
counter.innerText = "0";
const updateCounter = () => {
const target = +counter.getAttribute("data-target");
const c = +counter.innerText;
const increment = target / 200;
if(c < target) {
counter.innerText = `${Math.ceil(c + increment)}`
setTimeout(updateCounter, 1)
} else {
counter.innerText = target;
}
}
updateCounter();
})
728x90
LIST
'Javascript' 카테고리의 다른 글
Javascript - Notes App (0) | 2021.10.24 |
---|---|
Javascript - Live User Filter (0) | 2021.10.23 |
Javascript - Hoverboard (0) | 2021.10.20 |
Javascript - Github Profiles (0) | 2021.10.19 |
Javascript - Feedback UI Design (0) | 2021.10.18 |