Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vishnukumarpv/e1826df611aa490cc52911bde658de11 to your computer and use it in GitHub Desktop.
Save vishnukumarpv/e1826df611aa490cc52911bde658de11 to your computer and use it in GitHub Desktop.
//scroll to section with "data-anchor"
var $ = jQuery.noConflict();
$(' ul.mega-sub-menu li a.mega-menu-link').click(function(event){
event.preventDefault();
var url=$(this).attr('href');
var i= url.split('#')[1];
if($('[data-anchor="#'+i+'"]').length){ //*****using data-anchor******
jQuery('html, body').animate({
scrollTop: jQuery( '#'+i ).offset().top- 180
}, 500);
}else{
window.location= url;
}
});
//******************************************************************************************
//scroll to section "id" without "data-anchor"
var $ = jQuery.noConflict();
$(' ul.mega-sub-menu li a.mega-menu-link').click(function(event){
event.preventDefault();
var url=$(this).attr('href');
var i= url.split('#')[1];
if($('#'+i).length){
jQuery('html, body').animate({
scrollTop: jQuery( '#'+i ).offset().top-180
}, 500);
}else{
window.location= url;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment