Skip to content

Instantly share code, notes, and snippets.

@garystorey
Created September 17, 2014 16:41
Show Gist options
  • Select an option

  • Save garystorey/c8d9dc56c14e980c1e78 to your computer and use it in GitHub Desktop.

Select an option

Save garystorey/c8d9dc56c14e980c1e78 to your computer and use it in GitHub Desktop.
instead of if..else to add and remove class, use toggle with logic
/* This */
if (this.scrollTop > 147) {
wrap.addClass("fix-search");
} else {
wrap.removeClass("fix-search");
}
/* Becomes This */
wrap.toggleClass("fix-search", this.scrollTop > 147);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment