From b69cad8b845596fdd162a4910fb73e239505760b Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 10 Nov 2014 21:11:07 -0600 Subject: [PATCH] refactor(scrollBar): rAF scrollbar transitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only make changes to the scrollbar element’s style when there is a change, and use requestAnimationFrame when there is a change. --- js/views/scrollView.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/js/views/scrollView.js b/js/views/scrollView.js index 1471af016e..7fecb73b1f 100644 --- a/js/views/scrollView.js +++ b/js/views/scrollView.js @@ -972,7 +972,9 @@ ionic.views.Scroll = ionic.views.View.inherit({ width = 0; } if (width !== self.__indicatorX.size) { - self.__indicatorX.indicator.style.width = width + 'px'; + ionic.requestAnimationFrame(function(){ + self.__indicatorX.indicator.style.width = width + 'px'; + }); } self.__indicatorX.size = width; self.__indicatorX.minScale = self.options.minScrollbarSizeX / width; @@ -987,7 +989,9 @@ ionic.views.Scroll = ionic.views.View.inherit({ height = 0; } if (height !== self.__indicatorY.size) { - self.__indicatorY.indicator.style.height = height + 'px'; + ionic.requestAnimationFrame(function(){ + self.__indicatorY.indicator.style.height = height + 'px'; + }); } self.__indicatorY.size = height; self.__indicatorY.minScale = self.options.minScrollbarSizeY / height; @@ -1045,7 +1049,11 @@ ionic.views.Scroll = ionic.views.View.inherit({ } - self.__indicatorX.indicator.style[self.__transformProperty] = 'translate3d(' + x + 'px, 0, 0) scaleX(' + widthScale + ')'; + var translate3dX = 'translate3d(' + x + 'px, 0, 0) scaleX(' + widthScale + ')'; + if (self.__indicatorX.transformProp !== translate3dX) { + self.__indicatorX.indicator.style[self.__transformProperty] = translate3dX; + self.__indicatorX.transformProp = translate3dX; + } } if (self.__indicatorY) { @@ -1091,10 +1099,10 @@ ionic.views.Scroll = ionic.views.View.inherit({ } - var translate3d = 'translate3d(0,' + y + 'px, 0) scaleY(' + heightScale + ')'; - if (self.__indicatorY.transformProp !== translate3d) { - self.__indicatorY.indicator.style[self.__transformProperty] = translate3d; - self.__indicatorY.transformProp = translate3d; + var translate3dY = 'translate3d(0,' + y + 'px, 0) scaleY(' + heightScale + ')'; + if (self.__indicatorY.transformProp !== translate3dY) { + self.__indicatorY.indicator.style[self.__transformProperty] = translate3dY; + self.__indicatorY.transformProp = translate3dY; } } },