* Add debounce function taken from https://davidwalsh.name/javascript…#249
* Add debounce function taken from https://davidwalsh.name/javascript…#249SwiftThemes wants to merge 2 commits intogarand:masterfrom
Conversation
SwiftThemes
commented
Mar 14, 2017
- Add debounce function taken from https://davidwalsh.name/javascript-debounce-function to scroll and resize event listeners so that the functions are not executed multiple times.
- Remove height attribute from sticky wrapper when unstuck.
…-debounce-function to scroll and resize event listeners. * Remove height attribute from sticky wrapper when unstuck.
|
Hi @SwiftThemes Thanks for the debounce solution. However, with scroll, would you not want to be throttling rather than debouncing? Looking at the number of pull requests, it feels like the author may not be actively maintaining. So I thought maybe we can just discuss directly here. I am trying to use this for a project here http://www.nova969.com.au/nova969 And I have throttled (250ms) before calling the function. Yet, you will notice that there is a lag at the end. That is, at the end, as you scroll, the top position is constantly calculated and it feels like there is a huge lagging. ANy idea? |
|
Problem with throttle is, if the function is executed just before it should be unstuck, it won't get to its original position once its no longer hidden. I did not know about throttle before you mentioned it, so my understanding may be wrong. I tested both and 1'm good with deboucen @50ms. Problem with debounce is, it won't stick immediately, but for my use case 50ms is ok. But if I can get throttle to execute once the event is completely stopped, that would be perfect. Here are my functions |
|
I just added callback call in set timeout, I'm having very good results UX wise event at 200ms function throttle (callback, limit) { |