/* * jQuery.anchorSmooth * * * */ ;(function ($, window, undefined ) { var loc = window.location; $.fn.anchorSmoothScroll = function (options) { var $this = this; var conf = $.extend({ 'evt' : 'click', 'easing' : 'swing', 'duration' : 1000, 'notSelecter' : '', 'callback' : function(){} },options || {}); var cb = conf.callback; return $this.each (function (i) { var sameFile = function (el) { if (!el) return; if (!!el.length) el = el.get(); var chk = loc.pathname.replace(/^\//, '') === el.pathname.replace(/^\//, '') && loc.hostname === el.hostname; if (!chk) return false; var target = $(el.hash); target = target.length && target || $('[name=' + el.hash.slice(1) + ']'); if (!!target.length) { return { from : el, to : target.get(0), offset : target.offset() }; } }; $this.find('a[href*=#]').filter(function(){ if (!$(this).closest(conf.notSelecter).length) return $(this); }).on(conf.evt, function() { var obj = sameFile(this); //console.log(sameFile(this)); if (typeof obj.offset !== 'undefined') { $('html,body').animate({ scrollTop: obj.offset.top },{ easing: conf.easing, duration: conf.duration, complete : cb && cb.call(this,obj), step: function () {}, queue: false } ); return false; } }); }); }; })(jQuery, this, undefined);