NavBar kind of jerky (jQuery, html, css) -


i have problem navbar being jerky time time. doesn't happen time, funny bothers me when does. problem when scrolling up/down @ beginning, kind of lags on openning/closing. i'm using google chrome.

it's made using html, css , jquery. here's codepan link: https://codepen.io/jhnsnw/pen/prlwxa

i tried things read online on similar issues, didn't work. kind of great. thanks.

the window.scroll gets fired for every scrolled pixel (at least in firefox), i'm guessing might have effect , performace. limit amount of events, there dethrottle, or deboucen.

this webpage has nice plugin , explains well:

a visualization

while $.throttle designed throttle callback execution, behaves differently based on how no_trailing parameter used.

throttled no_trailing specified false or unspecified: enter image description here

the first line amount of triggered event, second line detrottled version might fire e.g. every 50ms (which still fast!).


the other solution might apply, logic function. in code, have if/else. if scroll, always apply removeclass or addclass not best choice performance.
can remember wether or not past threshold, , fire when changes again:

if (scrolled > navheight){     if( !scrolledpastthreshold ){         $('.page-nav').addclass('off-canvas');         scrolledpastthreshold = true;     } } else {     if( scrolledpastthreshold ){         $('.page-nav').removeclass('off-canvas');         scrolledpastthreshold = false;     } }   

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -