w3.css
곧 출시 페이지
CSS와 JavaScript를 사용하여 ‘곧 출시 페이지’를 만드는 방법을 알아보자.
곧 출시 페이지를 만드는 방법
1단계) HTML 추가
우리의 예시에서는 전체 페이지를 덮는 배경 이미지를 사용하고 이미지에 텍스트를 넣어 사용자에게 무슨 일이 일어나고 있는지 알려준다.
이 예제는 HTML과 CSS만으로 “Coming Soon Page”를 만드는 방법을 보여준다.
다음 예제를 살펴보면 JavaScript로 “카운트다운 타이머”를 추가하는 방법도 알 수 있다.
<div class="bgimg"> <div class="topleft"> <p>Logo</p> </div> <div class="middle"> <h1>COMING SOON</h1> <hr> <p>35 days</p> </div> <div class="bottomleft"> <p>Some text</p> </div> </div>
2단계) CSS 추가
/* Set height to 100% for body and html to enable the background image to cover the whole page: */ body, html { height: 100% } .bgimg { /* Background image */ background-image: url('/w3images/forestbridge.jpg'); /* Full-screen */ height: 100%; /* Center the background image */ background-position: center; /* Scale and zoom in the image */ background-size: cover; /* Add position: relative to enable absolutely positioned elements inside the image (place text) */ position: relative; /* Add a white text color to all elements inside the .bgimg container */ color: white; /* Add a font */ font-family: "Courier New", Courier, monospace; /* Set the font-size to 25 pixels */ font-size: 25px; } /* Position text in the top-left corner */ .topleft { position: absolute; top: 0; left: 16px; } /* Position text in the bottom-left corner */ .bottomleft { position: absolute; bottom: 0; left: 16px; } /* Position text in the middle */ .middle { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; } /* Style the
element */ hr { margin: auto; width: 40%; }
기본 예시
예제 보기3단계) JavaScript 추가
카운트다운 타이머를 생성하려면 JavaScript를 추가하자.
// Set the date we're counting down to var countDownDate = new Date("Jan 5, 2024 15:37:25").getTime(); // Update the count down every 1 second var x = setInterval(function() { // Get todays date and time var now = new Date().getTime(); // Find the distance between now an the count down date var distance = countDownDate - now; // Time calculations for days, hours, minutes and seconds var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Display the result in an element with id="demo" document.getElementById("demo").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s "; // If the count down is finished, write some text if (distance < 0) { clearInterval(x); document.getElementById("demo").innerHTML = "EXPIRED"; } }, 1000);
기본 예시
예제 보기참고
W3C School - Coming Soon Page