diff --git a/jquery.smoothscroll.js b/jquery.smoothscroll.js index c926b25..ad4a3bb 100644 --- a/jquery.smoothscroll.js +++ b/jquery.smoothscroll.js @@ -1,4 +1,5 @@ -/* +/** + * @preserve * jquery.smoothscroll.js - jQuery plugin to animate scrolling to anchor links * Version 1.0.4 (Aug 19, 2017) * Copyright 2017 Kite - https://github.com/ixkaito @@ -30,7 +31,7 @@ ) { // Figure out element to scroll to var hash = this.hash; - var $target = $(hash); + var $target = hash ? $(hash) : $('html'); $target = $target.length ? $target : $('[name=' + this.hash.slice(1) + ']'); // Does a scroll target exist? if ($target.length) { diff --git a/jquery.smoothscroll.min.js b/jquery.smoothscroll.min.js index 2a721e0..f090d4a 100644 --- a/jquery.smoothscroll.min.js +++ b/jquery.smoothscroll.min.js @@ -1,11 +1,8 @@ -/* +/** + * @preserve * jquery.smoothscroll.js - jQuery plugin to animate scrolling to anchor links * Version 1.0.4 (Aug 19, 2017) * Copyright 2017 Kite - https://github.com/ixkaito * MIT License */ -/* eslint-disable no-var, no-invalid-this */ -(function(a,b){a.fn.smoothscroll=function(d){var e={duration:400,easing:"swing",offset:0,hash:true,focus:true,};var c=a.extend(true,{},e,d);return this.each(function(){a(this).on("click",function(g){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var h=this.hash; -var f=a(h);f=f.length?f:a("[name="+this.hash.slice(1)+"]");if(f.length){g.preventDefault();a("html, body").stop().animate({scrollTop:f.offset().top+c.offset,},c.duration,c.easing,function(){if(c.hash){if(history.pushState){history.pushState(null,null,h); -}else{if(0==c.offset){window.location.hash=h;}else{var i=(c.offset>0?"+":"-");window.location.hash=h+"-offset-"+i+Math.abs(c.offset);}}}if(c.focus){f.focus(); -if(f.is(":focus")){return false;}else{f.attr("tabindex","-1");f.focus();}}});}}});});};})(jQuery); +(function($,undefined){"use strict";$.fn.smoothscroll=function(options){var defaults={duration:400,easing:"swing",offset:0,hash:true,focus:true};var config=$.extend(true,{},defaults,options);return this.each(function(){$(this).on("click",function(event){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var hash=this.hash;var $target=hash?$(hash):$("html");$target=$target.length?$target:$("[name="+this.hash.slice(1)+"]");if($target.length){event.preventDefault();$("html, body").stop().animate({scrollTop:$target.offset().top+config.offset},config.duration,config.easing,function(){if(config.hash){if(history.pushState){history.pushState(null,null,hash)}else if(0==config.offset){window.location.hash=hash}else{var operator=config.offset>0?"+":"-";window.location.hash=hash+"-offset-"+operator+Math.abs(config.offset)}}if(config.focus){$target.focus();if($target.is(":focus")){return false}else{$target.attr("tabindex","-1");$target.focus()}}})}}})})}})(jQuery); \ No newline at end of file