Skip to content

Instantly share code, notes, and snippets.

@jerinisready
Created June 20, 2019 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerinisready/5b938c023023990c025c0a52cf3eb1ec to your computer and use it in GitHub Desktop.
Save jerinisready/5b938c023023990c025c0a52cf3eb1ec to your computer and use it in GitHub Desktop.
How to make li.active list element in side-menu to display screen
<script>
let el = document.querySelector('.scrollbar li.active');
let elementTop = $(el).offset().top;
let elementBottom = elementTop + $(el).outerHeight();
let viewportTop = $(window).scrollTop();
let viewportBottom = viewportTop + $(window).height() - 80;
if(!(elementBottom > viewportTop && elementTop < viewportBottom)){
el.scrollIntoView()
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment