Sunday 18 August 2019

Adding Anchor to a menu in a website

This code is for HTML
 <li> <a href="#A1">Jump </a></li>  <div id="A1"> </div>

This code is for WordPress
Go to Dashboard -> appearance -> menus -> custom links -> #A1 (This will be the URL)

Now go to the page where you want this to work 

<h1 id="A1"> Jump here </h1>

To add Scrolling effect to the anchor 
$function(){
$(''a[href *=# ]: not ([href =#])').click(function(){
if(location.pathname.replace(/^\ //,' ') == this.pathname.replace(/^\ //,'') && location.hostname == this.hostname){
Var target = $(this.hash);
target=target.length ? target:$('[name='+this.hash.slice(1)+']');

if (target.length){
$('html,body').animate({
scrollTop: target.offset().top
},1000);

return false;
}
}
});
});