javascript - how to change color of navigation link -


i creating website in using hash tag different links such home contact etc. want navigation button should change color #03c1cb when address of url describes particular hash tab. eg when url shows #home ,the link name home's color should change , rest of link should have white color. rest of links. please me how do.i positing code. html code is

<span><a href="#home" id="start1" class="navlink" style="text-decoration:none;position:absolute;right:450px;top:37px;font-weight:bold;color:white;font-size:15px;z-index:200;transition:0.5s"  onmouseover="big(this)" onmouseout="small(this)">home</a></span> <span><a href="#products" id="start2" class="navlink" style="text-decoration:none;position:absolute;right:250px;top:37px;font-weight:bold;color:white;font-size:15px;transition:0.5s" onmouseover="big(this)" onmouseout="small(this)">products & services</a></span> <span><a href="#about" id="start3" class="navlink" style="text-decoration:none;position:absolute;right:140px;top:37px;font-weight:bold;color:white;font-size:15px;transition:0.5s" onmouseover="big(this)" onmouseout="small(this)">about us</a></span> <span><a href="#contacts" id="start4" class="navlink" style="text-decoration:none;position:absolute;right:20px;top:37px;font-weight:bold;color:white;font-size:15px;transition:0.5s" onmouseover="big(this)" onmouseout="small(this)">contact us</a></span> </p> 

and js code

function iselementinviewport (el) {       //special bonus using jquery       if (typeof jquery === "function" && el instanceof jquery) {         el = el[0];       }       var rect = el.getboundingclientrect();       return (         rect.top >= 0 &&         rect.left >= 0 &&         rect.bottom <= (window.innerheight || document.documentelement.clientheight) && /*or $j(window).height() */         rect.right <= (window.innerwidth || document.documentelement.clientwidth) /*or $j(window).width() */       );     }  // url change on clicking $j(document).ready(function () {     $j("#start1,#start2,#start3,#start4,#start5,#start6").click(function (e) {         e.preventdefault();         var section = this.href,             sectionclean = section.substring(section.indexof("#"));          $j("html, body").animate({             scrolltop: $j(sectionclean).offset().top         }, 1000, function () {             window.location.hash = sectionclean;         });     }); }); // listen scroll event     $j(document).on("scroll", function() {       console.log("onscroll event fired...");       // check if anchor elements visible       $j(".anchor").each(function (idx, el) {         if ( iselementinviewport(el) ) {           // update url hash           if (window.history.pushstate) {             var urlhash = "#" + $j(el).attr("id");             window.history.pushstate(null, null, urlhash);           }         }       });     }); function big(x){  x.style.fontsize = "17px"; x.style.color="#03c1cb"; } function small(x){  x.style.fontsize = "15px"; x.style.color="white";  } 

please me how ?

try this...

<style> .[element].active{   color: [color]; } </style> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -