html - JQuery script probably syntax mistake -
i don't know jquery, have script.js file:
$(document).ready(function() { var main_nav = $("#main-nav"); var main_section = $("#main-section"); var main_footer = $("#main-footer"); var main_nav_position = main_nav.position(); $(window).scroll(function() { if ($(window).scrolltop() >= main_nav_position.top) { main_nav.addclass("main-nav-sticky"); main_section.addclass("sticky-adjust"); main_footer.addclass("sticky-adjust"); } else { main_nav.removeclass("main-nav-sticky"); main_section.removeclass("sticky-adjust"); main_footer.removeclass("sticky-adjust"); } }); }); $(document).ready(function() { switch (window.location.pathname) { case 'index.html': $('#shop-button').attr('id','shop-button-disabled'); break; case 'staff.html': $('#staff-button').attr('id','staff-button-disabled'); break; case 'contact.html': $('#contact-button').attr('id','contact-button-disabled'); break; } });
the first script works second doesn't. don't know if that's because of $(document).ready(function() or because of switch-case istance. there problem or css/html fault? thanks!
the value returned window.location.pathname
starts /
, should change switch statement reflect this
$(document).ready(function() { switch (window.location.pathname) { case '/index.html': $('#shop-button').attr('id','shop-button-disabled'); break; case '/staff.html': $('#staff-button').attr('id','staff-button-disabled'); break; case '/contact.html': $('#contact-button').attr('id','contact-button-disabled'); break; } });
Comments
Post a Comment