javascript - Fixed navbar hides web content and JS is not working -


this happen when press button "contacto"

enter image description here

and should

enter image description here

and i'm using javascript code

    $(function(){     $('a#boton-contacto').on('click',function(e){         e.preventdefault();         var strancla = $(this).attr('href');          $('body,html').stop(true ,true).animate({             scrolltop: $(strancla).offset().top - $('nav').height()         }, 500);      }); }); 

but made button stop working, want know why, wrong?

you can go site , try http://genebi.net hope can me, thanks.

this code jquery:

var strancla = $(this).attr('href'); setting strancla "http://genebi.net/#contacto"

and since "http://genebi.net/#contacto" not valid selector, there javascript error prevents code running.

to solve this, either:

  1. change url element from: <a id="boton-contacto" href="http://genebi.net/#contacto">contacto</a>

to <a id="boton-contacto" href="http://genebi.net/#contacto">contacto</a>

or:

2: use data attribute in link:

<a id="boton-contacto" href="http://genebi.net/#contacto" data-element="#contacto">contacto</a>

and alter jquery follows:

var strancla = $(this).attr('data-element');

and work desire.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -