javascript - Fixed navbar hides web content and JS is not working -
this happen when press button "contacto"

and should

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:
- 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
Post a Comment