From 0b9ef41f8507b6d5f11b4c42d57397e9a1850402 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 29 Nov 2015 15:50:19 +0800 Subject: [PATCH] replace setTimeout with requestAnimationFrame --- src/module/Select.jsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/module/Select.jsx b/src/module/Select.jsx index b386d07..0b91ac5 100644 --- a/src/module/Select.jsx +++ b/src/module/Select.jsx @@ -3,6 +3,10 @@ import ReactDom from 'react-dom'; import classnames from 'classnames'; const scrollTo = (element, to, duration) => { + const requestAnimationFrame = window.requestAnimationFrame || + function requestAnimationFrameTimeout() { + return setTimeout(arguments[0], 10); + }; // jump to target if duration zero if (duration <= 0) { element.scrollTop = to; @@ -11,11 +15,11 @@ const scrollTo = (element, to, duration) => { const difference = to - element.scrollTop; const perTick = difference / duration * 10; - setTimeout(() => { + requestAnimationFrame(() => { element.scrollTop = element.scrollTop + perTick; if (element.scrollTop === to) return; scrollTo(element, to, duration - 10); - }, 10); + }); }; const Select = React.createClass({ -- 2.41.0