perfect-scrollbar/min/perfect-scrollbar.min.js

1 line
7.1 KiB
JavaScript
Raw Normal View History

!function($){var defaultSettings={wheelSpeed:10,wheelPropagation:false};$.fn.perfectScrollbar=function(suppliedSettings,option){return this.each(function(){var settings=$.extend(true,{},defaultSettings);if(typeof suppliedSettings==="object"){$.extend(true,settings,suppliedSettings)}else{option=suppliedSettings}if(option==="update"){if($(this).data("perfect-scrollbar-update")){$(this).data("perfect-scrollbar-update")()}return $(this)}else if(option==="destroy"){if($(this).data("perfect-scrollbar-destroy")){$(this).data("perfect-scrollbar-destroy")()}return $(this)}if($(this).data("perfect-scrollbar")){return $(this).data("perfect-scrollbar")}var $this=$(this).addClass("ps-container"),$content=$(this).children(),$scrollbarX=$("<div class='ps-scrollbar-x'></div>").appendTo($this),$scrollbarY=$("<div class='ps-scrollbar-y'></div>").appendTo($this),containerWidth,containerHeight,contentWidth,contentHeight,scrollbarXWidth,scrollbarXLeft,scrollbarXBottom=parseInt($scrollbarX.css("bottom"),10),scrollbarYHeight,scrollbarYTop,scrollbarYRight=parseInt($scrollbarY.css("right"),10);var updateContentScrollTop=function(){var scrollTop=parseInt(scrollbarYTop*contentHeight/containerHeight,10);$this.scrollTop(scrollTop);$scrollbarX.css({bottom:scrollbarXBottom-scrollTop})};var updateContentScrollLeft=function(){var scrollLeft=parseInt(scrollbarXLeft*contentWidth/containerWidth,10);$this.scrollLeft(scrollLeft);$scrollbarY.css({right:scrollbarYRight-scrollLeft})};var updateBarSizeAndPosition=function(){containerWidth=$this.width();containerHeight=$this.height();contentWidth=$content.outerWidth(false);contentHeight=$content.outerHeight(false);if(containerWidth<contentWidth){scrollbarXWidth=parseInt(containerWidth*containerWidth/contentWidth,10);scrollbarXLeft=parseInt($this.scrollLeft()*containerWidth/contentWidth,10)}else{scrollbarXWidth=0;scrollbarXLeft=0;$this.scrollLeft(0)}if(containerHeight<contentHeight){scrollbarYHeight=parseInt(containerHeight*containerHeight/contentHeight,10);scrollbarYTop=parseInt($this.scrollTop()*containerHeight/contentHeight,10)}else{scrollbarYHeight=0;scrollbarYTop=0;$this.scrollTop(0)}if(scrollbarYTop>=containerHeight-scrollbarYHeight){scrollbarYTop=containerHeight-scrollbarYHeight}if(scrollbarXLeft>=containerWidth-scrollbarXWidth){scrollbarXLeft=containerWidth-scrollbarXWidth}$scrollbarX.css({left:scrollbarXLeft+$this.scrollLeft(),bottom:scrollbarXBottom-$this.scrollTop(),width:scrollbarXWidth});$scrollbarY.css({top:scrollbarYTop+$this.scrollTop(),right:scrollbarYRight-$this.scrollLeft(),height:scrollbarYHeight})};var moveBarX=function(currentLeft,deltaX){var newLeft=currentLeft+deltaX,maxLeft=containerWidth-scrollbarXWidth;if(newLeft<0){scrollbarXLeft=0}else if(newLeft>maxLeft){scrollbarXLeft=maxLeft}else{scrollbarXLeft=newLeft}$scrollbarX.css({left:scrollbarXLeft+$this.scrollLeft()})};var moveBarY=function(currentTop,deltaY){var newTop=currentTop+deltaY,maxTop=containerHeight-scrollbarYHeight;if(newTop<0){scrollbarYTop=0}else if(newTop>maxTop){scrollbarYTop=maxTop}else{scrollbarYTop=newTop}$scrollbarY.css({top:scrollbarYTop+$this.scrollTop()})};var bindMouseScrollXHandler=function(){var currentLeft,currentPageX;$scrollbarX.bind("mousedown.perfect-scroll",function(e){currentPageX=e.pageX;currentLeft=$scrollbarX.position().left;$scrollbarX.addClass("in-scrolling");e.stopPropagation();e.preventDefault()});$(document).bind("mousemove.perfect-scroll",function(e){if($scrollbarX.hasClass("in-scrolling")){moveBarX(currentLeft,e.pageX-currentPageX);updateContentScrollLeft();e.stopPropagation();e.preventDefault()}});$(document).bind("mouseup.perfect-scroll",function(e){if($scrollbarX.hasClass("in-scrolling")){$scrollbarX.removeClass("in-scrolling")}})};var bindMouseScrollYHandler=function(){var currentTop,currentPageY;$scrollbarY.bind("mousedown.perfect-scroll",function(e){currentPageY=e.pageY;currentTop=$scrollbarY.position().top;$scrollbarY.addClass("in-scrolling");e.stopPropagation();e.preventDefault()});$(document).bind("mousemove.perfect-scroll",function(e){if($scrollbarY.hasClass("in-scrolling")){moveBarY(curr