[JS] 로딩 (로드시 이벤트 설정하기)

2022. 6. 13. 15:53·Stack/JavaScript

방법 3가지 !

1. window.onload = function() {

            실행문

}

 

2. <body onload="loadingFunc()">

<script>

            function loadingFunc() {

                                실행문

            }

</script>

 

3.window.addEventListener("load", function() {

            실행문

})

 

 

 

* 인터넷 속도 넘 빨라서 window.onload = hideLoading; 대신 이렇게도 씀

function hideLoading() {

    let spinner = document.querySelector('#spinnerwrap');
    spinner.style.display = "none";
}

 

setTimeout(() => {
    // alert("로딩끝");
    hideLoading();
}, 2000);

 


 

html 블럭

<div id="spinnerwrap">
    <div class="spinner">
        <div class="bounce1"></div>
        <div class="bounce2"></div>
        <div class="bounce3"></div>
    </div>
</div>

 

script 블럭

<script>
    // window.onload = function() {
    //     alert("로딩끝");
    // }

    function hideLoading() {
        let spinner = document.querySelector('#spinnerwrap');
        spinner.style.display = "none";
    }

    // setTimeout(() => {
    //     // alert("로딩끝");
    //     hideLoading();
    // }, 2000);

    window.onload = hideLoading;
</script>

 

css 블럭

#spinnerwrap {
    position: absolute;
    top: 0;
    left: 0;
    background-image: linear-gradient(to top, #fbc2eb 0%, #a6c1ee 100%);;
    width: 100%;
    height: 100%;
}
.spinner {
    margin: 100px auto 0;
    width: 70px;
    text-align: center;
  }
  
  .spinner > div {
    width: 18px;
    height: 18px;
    background-color: #333;
  
    border-radius: 100%;
    display: inline-block;
    -webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
    animation: sk-bouncedelay 1.4s infinite ease-in-out both;
  }
  
  .spinner .bounce1 {
    -webkit-animation-delay: -0.32s;
    animation-delay: -0.32s;
  }
  
  .spinner .bounce2 {
    -webkit-animation-delay: -0.16s;
    animation-delay: -0.16s;
  }
  
  @-webkit-keyframes sk-bouncedelay {
    0%, 80%, 100% { -webkit-transform: scale(0) }
    40% { -webkit-transform: scale(1.0) }
  }
  
  @keyframes sk-bouncedelay {
    0%, 80%, 100% { 
      -webkit-transform: scale(0);
      transform: scale(0);
    } 40% { 
      -webkit-transform: scale(1.0);
      transform: scale(1.0);
    }
  }

 

https://tobiasahlin.com/spinkit/

 

SpinKit

Simple CSS Spinners

tobiasahlin.com

참조 ~

'Stack > JavaScript' 카테고리의 다른 글

[JS] 클래스 복습  (0) 2022.06.14
[JS] 배열 / 객체 / set 복습  (0) 2022.06.13
[JS] sarar  (0) 2022.06.13
[JS] 프로토타입  (0) 2022.05.23
[JS] 구조분해 할당  (0) 2022.05.23
'Stack/JavaScript' 카테고리의 다른 글
  • [JS] 클래스 복습
  • [JS] 배열 / 객체 / set 복습
  • [JS] sarar
  • [JS] 프로토타입
7ingout
7ingout
  • 7ingout
    Hello, 7ingout world!
    7ingout
  • 전체
    오늘
    어제
    • 분류 전체보기 (205)
      • Project (5)
      • Stack (173)
        • React (40)
        • JavaScript (50)
        • TypeScript (14)
        • HTML (11)
        • CSS (31)
        • Spring (9)
        • PHP (15)
        • SQL (3)
        • Python (0)
      • ETC (9)
      • Design (13)
        • Illustrator (6)
        • Photoshop (7)
      • Articloid (4)
        • 7ingout (4)
  • 공지사항

    • ☻
  • 인기 글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
7ingout
[JS] 로딩 (로드시 이벤트 설정하기)
상단으로

티스토리툴바