Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ADD ACTIVE CLASS FOR SIMPLE ELEMENT
- jQuery(document).ready(function(){
- jQuery('li a').click(function(){
- jQuery('li a').removeClass("active");
- jQuery(this).addClass("active");
- });
- });
- ADD ACTIVE CLASS FOR LINKS THAT RELOADS PAGE
- jQuery(document).ready(function () {
- const $links = jQuery('.gallery-link');
- jQuery.each($links, function (index, link) {
- if (link.href == document.URL) {
- jQuery(this).addClass('active');
- }
- });
- });
- ADD ACTIVE CLASS FOR ONE PAGE NAV
- const sections = document.querySelectorAll('.anchor-sections')
- function scrollActive(){
- const scrollY = window.pageYOffset
- sections.forEach(section => {
- const sectionHeight = section.offsetHeight,
- sectionTop = section.offsetTop - 150,
- sectionId = section.getAttribute('id')
- if(scrollY > sectionTop && scrollY <= sectionTop + sectionHeight){
- document.querySelector(' .menu-side-nav-container a[href*=' + sectionId + ']').classList.add('active')
- }else{
- document.querySelector(' .menu-side-nav-container a[href*=' + sectionId + ']').classList.remove('active')
- }
- })
- }
- window.addEventListener('scroll', scrollActive)
- //select first nav item via attribute
- const firstNav = document.querySelector('[title="cool link one"]');
- //add active class to firt nav item
- firstNav.classList.add('active');
Add Comment
Please, Sign In to add comment