-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoothScroll-1.0.min.js
8 lines (6 loc) · 4.18 KB
/
smoothScroll-1.0.min.js
1
2
3
4
5
6
7
8
/* Plugin asFastBar
scroll bar design pour votre site web
Developpée par Adam Santoro
http://asfastbar.adamsantoro.fr
*/
(function(a){a.fn.asFastBar=function(c){var d=a.extend({theme:"dark",autoHide:false,opacity:0.6,background:false,scrollSpeed:2,delayHideBar:1000,cssBar:false,cssBg:false,animate:true,a:false,b:false,c:0,d:0,t:0,f:false,e:null,x:function(){return parseInt(a("#asBar").css("top"))},g:function(){return parseInt(a("#asBarBody").css("top"))},h:function(){return a("#asBar").innerHeight()},i:function(){return a("#asBarBody").innerHeight()},j:function(){return a(document).scrollTop()},k:document.documentElement.clientHeight,n:a(document).innerHeight(),o:false,p:function(){return(new Date()).getTime()},q:null,z:false,u:false,v:0,w:false,r:function(){d.k=document.documentElement.clientHeight;d.n=a(document).innerHeight()}},c);d.scrollSpeed=d.scrollSpeed>3?3:d.scrollSpeed;var b={i:function(){if(!document.getElementById("asBar")){a("html").css("overflow","hidden");d.e=a.browser.chrome?document.body:document.documentElement;d.o=d.autoHide?false:true;a("body").append(a(document.createElement("div")).attr({id:"asBar"}));a("#asBar").append(a(document.createElement("div")).attr({id:"asBarBody"}));b.s();var g=d.theme=="dark"?"#000":"#fff",e="transparent",f=0;if(d.background){e=d.theme=="dark"?"#fff":"#000";f=d.opacity}a("#asBar").css({background:e,opacity:f});a("#asBarBody").css({background:g});a("#asBar, #asBarBody").css({position:"fixed",right:"2px",top:"7px",width:"8px"});if(d.cssBg){a("#asBar").css(d.cssBg)}if(d.cssBar){a("#asBarBody").css(d.cssBar)}!d.o?a("#asBar, #asBarBody").css("opacity",0):a("#asBar, #asBarBody").css("opacity",0);b.c()}},s:function(){d.u=setTimeout(function(){if((d.p()/1000).toFixed(1)-(d.v/1000).toFixed(1)>=0.5){d.r();a("#asBar").css("height",(d.k-14)+"px");a("#asBarBody").css("height",((d.k-14)/(d.n/d.k))+"px");b.b()}},500)},b:function(){if(!d.w){var f=(d.j()/(d.n/d.k)),e=d.x();f=f<e?e:f;d.animate?a("#asBarBody").animate({top:f+"px"},{duration:20}):a("#asBarBody").css({top:f+"px"})}else{d.w=false}d.u=false},h:function(){d.z=setTimeout(function(){if(!d.b){if(Math.round(d.p()/1000)-d.q>=d.delayHideBar/1000){d.o=false;a("#asBar, #asBarBody").animate({opacity:0},"slow")}}},d.delayHideBar)},o:function(){if(!d.o){d.o=true;a("#asBar, #asBarBody").animate({opacity:d.opacity},"fast")}},c:function(){setInterval(function(){if(!d.u){b.s()}},1000)}};return this.each(function(){$this=a(this);b.i.call(window);console.log(d.n);var e=a.browser.mozilla||(a.browser.opera&&a.browser.version<=10)?"DOMMouseScroll":"mousewheel";a(this).scroll(function(){if(!d.a){b.b()}});a(window).resize(function(){d.v=d.p();if(d.u){clearTimeout(d.u);d.u=false}b.s()});a(this).bind(e+" keydown",function(i){var g=d.j();var f=25*d.scrollSpeed;var j=a.browser.mozilla||(a.browser.opera&&a.browser.version<=10)?-i.originalEvent.detail:i.originalEvent.wheelDelta;if(j>=0||(!j&&i.keyCode==38)){if(g>0&&g<f){scrollTo(0,0)}else{if(g>0){scrollBy(0,-f)}}}else{if(j<0||(!j&&i.keyCode==40)){scrollBy(0,f)}}if(d.autoHide){d.q=Math.round(d.p()/1000);if(d.z){clearTimeout(d.z);d.z=false}b.h();b.o()}});a(document).on("dragstart",function(f){return false});a(document).on("mousedown","#asBarBody",function(f){a("html").attr("unselectable","on").css("user-select","none");d.a=true;d.c=f.pageY-d.j();d.d=d.c-d.g();d.t=a(f.target);f.stopImmediatePropagation()}).on("mouseup",function(){if(d.a){d.a=false;a("html").removeAttr("unselectable").css("user-select","all");if(d.autoHide&&d.o){setTimeout(function(){if(d.o&&!d.b){a("#asBar, #asBarBody").animate({opacity:0},"slow");d.o=false}},d.delayHideBar)}}d.t=null});a(a(this)).on("mousemove",function(f){if(d.a&&!d.f&&d.t){d.f=true;setTimeout(function(){var n=d.j(),q=d.g(),k=d.x(),p=d.h(),o=d.i(),l=(f.pageY-n)-d.d,m=0;if(k&&d.t!=null){m=l>k?l:k;if(l>p-o){m=p-o+k}d.animate?d.t.animate({top:m+"px"},{duration:40}):d.t.css({top:m+"px"});a(d.e).scrollTop(parseInt((d.n-d.k)*(q-k)/(p-o)));d.w=true}console.log(l);d.f=false},80)}});if(d.autoHide){a(document).on("mouseenter","#asBar",function(f){if(d.autoHide){b.o()}d.b=true}).on("mouseleave","#asBar",function(f){if(!d.a){setTimeout(function(){if(!d.o){a("#asBar, #asBarBody").animate({opacity:0},"slow")}},d.delayHideBar);d.o=false}d.b=false})}})}})(jQuery);