UNPKG

jquery-gotop

Version:

goTop is a <2kb Scroll to Top jQuery plugin.

7 lines 1.27 kB
/*! * jQuery goTop v2.0.0 (https://github.com/scottdorman/jquery-gotop) * Copyright 2015 Scott Dorman (@sdorman) * Licensed under MIT (https://github.com/scottdorman/jquery-gotop/blob/master/LICENSE) * Adapted from goUp originally developed by Roger Vila (@_rogervila) */ (function(n){n.fn.goTop=function(t){n.fn.goTop.defaults={container:"",appear:200,scrolltime:800,src:"fas fa-chevron-up",width:45,place:"right",fadein:500,fadeout:500,opacity:.5,marginX:2,marginY:2,zIndex:9};var i=n.extend({},n.fn.goTop.defaults,t);return this.each(function(){var u=n(this);u.html("<a id='goTopAnchor'><span id='goTopSpan' /><\/a>");var r=u.children("a"),t=r.children("span"),f={position:"fixed",display:"block",width:"'"+i.width+"px'","z-index":i.zIndex,bottom:i.marginY+"%"};f[i.place==="left"?"left":"right"]=i.marginX+"%";u.css(f);r.css("opacity",i.opacity);t.addClass(i.src);t.css("font-size",i.width);t.hide();n(function(){n(i.container||window).scroll(function(){n(this).scrollTop()>i.appear?t.fadeIn(i.fadein):t.fadeOut(i.fadeout)});n(r).hover(function(){n(this).css("opacity","1.0");n(this).css("cursor","pointer")},function(){n(this).css("opacity",i.opacity)});n(r).click(function(){return n("body,html").animate({scrollTop:0},i.scrolltime),!1})})})}})(jQuery);