From a2e458d0aee9ff190ef81ea714283d33c050d1f5 Mon Sep 17 00:00:00 2001 From: smiler-xu Date: Fri, 21 Nov 2014 17:44:15 +0800 Subject: [PATCH] =?UTF-8?q?update=E6=96=B9=E6=B3=95=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update方法增加animate及duration参数 --- lib/jquery.tinyscrollbar.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/jquery.tinyscrollbar.js b/lib/jquery.tinyscrollbar.js index e014d71..f5911c1 100644 --- a/lib/jquery.tinyscrollbar.js +++ b/lib/jquery.tinyscrollbar.js @@ -71,7 +71,7 @@ return self; } - this.update = function(scrollTo) + this.update = function(scrollTo,animate,duration) { var sizeLabelCap = sizeLabel.charAt(0).toUpperCase() + sizeLabel.slice(1).toLowerCase(); this.viewportSize = $viewport[0]['offset'+ sizeLabelCap]; @@ -97,15 +97,25 @@ this.contentPosition = parseInt(scrollTo, 10) || 0; } - setSize(); + setSize(animate,duration); return self; }; - function setSize() + function setSize(animate,duration) { - $thumb.css(posiLabel, self.contentPosition / self.trackRatio); - $overview.css(posiLabel, -self.contentPosition); + if(!!animate){ + if(posiLabel == 'left'){ + $thumb.stop(true,false).animate({left : self.contentPosition / self.trackRatio},(parseInt(duration) || 200)); + $overview.stop(true,false).animate({left : -self.contentPosition},(parseInt(duration) || 200)); + }else if(posiLabel == 'top'){ + $thumb.stop(true,false).animate({top : self.contentPosition / self.trackRatio},(parseInt(duration) || 200)); + $overview.stop(true,false).animate({top : -self.contentPosition},(parseInt(duration) || 200)); + } + }else{ + $thumb.css(posiLabel, self.contentPosition / self.trackRatio); + $overview.css(posiLabel, -self.contentPosition); + } $scrollbar.css(sizeLabel, self.trackSize); $track.css(sizeLabel, self.trackSize); $thumb.css(sizeLabel, self.thumbSize);