jquery - animate scrolling matching the name not working fine -
$("a.scroll").click(function(){ if(this.hash){ //get rid of hash var hash = this.hash.substr(1); //get position of <a name> var $toelement = $("a[name="+hash+"]"); var toposition = $toelement.offset().top - 250; //scroll/animate element $("body,html").animate({ scrolltop : toposition },1000,"easeoutexpo"); return false; } }); if(location.hash){ var hash = location.hash; window.scroll(0,0); $("a[href="+hash+"]").click(); }
when trying match name string , scrolling location hiding behind header, header fixed.. on scrolling..
and facing problem when resize window, header takes space , scrolling hides content behind.. how fix it//
the <a>
element doesn't have hash
member. check console errors before posting. need href
attribute's content. might needing this:
$("a.scroll").click(function() { var href = $(this).attr("href"); if (href.indexof("#") === 0) { //get rid of hash var hash = href.substr(1); //get position of <a name> var $toelement = $("a[name=" + hash + "]"); var toposition = $toelement.offset().top - 250; //scroll/animate element $("body,html").animate({ scrolltop: toposition }, 1000, "easeoutexpo"); return false; } });
Comments
Post a Comment