]> git.immae.eu Git - github/fretlink/time-picker.git/commitdiff
replace setTimeout with requestAnimationFrame
authorafc163 <afc163@gmail.com>
Sun, 29 Nov 2015 07:50:19 +0000 (15:50 +0800)
committerafc163 <afc163@gmail.com>
Sun, 29 Nov 2015 07:51:04 +0000 (15:51 +0800)
src/module/Select.jsx

index b386d071d6def84e2675e75b8a4a87dcc0b20fc5..0b91ac5516e0171bffffcee5f5aaf50007c93600 100644 (file)
@@ -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({