Why doesn't the navigation color change

Hi i am writing this code to change my url based navigation link color but it is not working as expected please help me. I want to change the color of the navigation link for that specific url my js code

function big(x){

x.style.fontSize = "17px";
x.style.color="#03c1cb";
}
function small(x){
var y=location.hash;
if(x.href== y){
x.style.fontSize = "17px";
x.style.color="#03c1cb";
}
else{
x.style.color = "white";
x.style.fontSize ="15px";
}
}

      

and

function isElementInViewport (el) {
      //special bonus for those 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
$(document).ready(function () {
    $(".scroll").click(function (e) {
        e.preventDefault();
        var section = this.href,
            sectionClean = section.substring(section.indexOf("#"));

        $("html, body").animate({
            scrollTop: $j(sectionClean).offset().top
        }, 1000, function () {
            window.location.hash = sectionClean;
        });

    });
});
// listen for the scroll event
    $(document).on("scroll", function() {
      console.log("onscroll event fired...");
      // check if the anchor elements are visible
      $(".anchor").each(function (idx, el) {
        if ( isElementInViewport(el) ) {
          // update the URL hash
          if (window.history.pushState) {
            var urlHash = "#" + $j(el).attr("id");
            window.history.pushState(null, null, urlHash);
          }
        }
      });
    });

      

and my html code

<a href="#home" id="start1" class="scroll" 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>

      

Please help me

+3


source to share


1 answer


You have made the href color white so you can't see it. Change the background color to a dark color



<!DOCTYPE html>

<head>
  <meta charset="utf-8">
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

  <style>
     body {background-color:lightgray}
  </style>
</head>
<body>
   <a href="#home" id="start1" class="scroll" 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>
<script>
   function big(x){
     console.log(x.id);
     var x = document.getElementById(x.id);
   x.style.fontSize = "17px";
   x.style.color="#03c1cb";
   }
   function small(x){
   var y=location.hash;
   if(x.href== y){
   x.style.fontSize = "17px";
   x.style.color="#03c1cb";
   }
   else{
   x.style.color = "white";
   x.style.fontSize ="15px";
   }
 }
   </script>
</body>
</html>

      

0


source







All Articles