코드노트

javascript lodash - throttle 사용방법 본문

Code note/자바스크립트

javascript lodash - throttle 사용방법

코드노트 2022. 5. 8. 18:54

cdn 설치

 

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
 

lodash.js - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers

A utility library delivering consistency, customization, performance, & extras. - Simple. Fast. Reliable. Content delivery at its finest. cdnjs is a free and open-source CDN service trusted by over 12.5% of all websites, serving over 200 billion requests e

cdnjs.com

 

 

- throttle : 이벤트가 반복적으로 실행되는 주기와 상관없이 초단위 시간으로 실행시킨다.

 

ex)
const badgeEl = document.querySelector('header .badges');

window.addEventListener('scroll', _.throttle(function() {
  console.log('scroll!');
}, 300)); // _.throttle(함수, 시간)