;(function($) { $.fn.anchorAnimate = function(settings) { settings = jQuery.extend({ speed : 1100, offset : 0 }, settings); return this.each(function(){ var caller = this; jQuery(caller).click(function (event) { event.preventDefault(); var locationHref = window.location.href; var elementClick = jQuery(caller).attr("href").replace('#',''); if(jQuery('#'+elementClick).length > 0){ // Make sure there's a destination to go to var destination = jQuery('*[name="'+elementClick+'"],*[id="'+elementClick+'"]').offset().top; jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination+settings.offset}, settings.speed, 'easeOutQuad', function() { window.location.hash = elementClick; }); return false; } }) }) } })(jQuery);