Skip to content

Instantly share code, notes, and snippets.

Avatar
☢️

Aviral Singh Chauhan sAVItar02

☢️
  • Bangalore, India
View GitHub Profile
@sAVItar02
sAVItar02 / navColorChange.js
Created Jul 14, 2021
Change background color of the navbar on scroll
View navColorChange.js
// JQuery
$(function (){
$(document).scroll(function(){
var $nav = $(".nav");
$nav.toggleClass("scrolled", $(this).scrollTop() > $nav.height()); // in the class "scrolled" set a different background color
});
});
// Vanilla
window.onscroll = function() {