(func, wait = 20, immediate = true)
| 1 | function debounce(func, wait = 20, immediate = true) { |
| 2 | var timeout; |
| 3 | return function() { |
| 4 | var context = this, args = arguments; |
| 5 | var later = function() { |
| 6 | timeout = null; |
| 7 | if (!immediate) func.apply(context, args); |
| 8 | }; |
| 9 | var callNow = immediate && !timeout; |
| 10 | clearTimeout(timeout); |
| 11 | timeout = setTimeout(later,wait); |
| 12 | if (callNow) func.apply(context, args); |
| 13 | }; |
| 14 | }; |
| 15 | |
| 16 | const sliderImages = document.querySelectorAll('.slide-in'); |
| 17 |