Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

active state of nav while scrolling

const links = document.querySelectorAll('.links');
const sections = document.querySelectorAll('section');

function changeLinkState() {
  let index = sections.length;

  while(--index && window.scrollY + 50 < sections[index].offsetTop) {}
  
  links.forEach((link) => link.classList.remove('active'));
  links[index].classList.add('active');
}

changeLinkState();
window.addEventListener('scroll', changeLinkState);
Comment

PREVIOUS NEXT
Code Example
Javascript :: logo ticker html javascript 
Javascript :: non-arrow functions are forbidden $(document).ready(function() { 
Javascript :: 419 Unknown status, csrf token required, ajax csrf setup 
Javascript :: js variable delete during loading page 
Javascript :: ionic react exit app 
Javascript :: change to kebabcase in javascript 
Javascript :: module scope javascript 
Javascript :: change env location react 
Javascript :: asasa 
Javascript :: find component inside tree with enzyme shallow wrapper 
Javascript :: angular form initialse 
Javascript :: react native bottom sheet example 
Javascript :: var = " "; 
Javascript :: Sub-routes in Main route not getting static files ExpressJS 
Javascript :: listen to keyboard close event in js 
Javascript :: javascript promise multi function error 
Javascript :: table antd dosen t update 
Javascript :: throttle ajax requests 
Javascript :: javascript interview quetions 
Javascript :: js particles without plugin 
Javascript :: utility javascript function list 
Javascript :: javascript synchronous and asynchronous list 
Javascript :: click outside button angular 
Javascript :: cypress json no videos 
Javascript :: jquery validate min and max value 
Javascript :: how to generate a random number between 1 and 6 in javascript 
Javascript :: converting jsObject to JSON 
Javascript :: react.js form 
Javascript :: Can Execute Backbone In RequireJS 
Javascript :: without the filter() method 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =