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;
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({
componentDidUpdate() {
// smooth scroll to selected option
- this.scrollToSelected(200);
+ this.scrollToSelected(120);
},
onSelect(value) {
// move to selected item
const select = ReactDom.findDOMNode(this);
const list = ReactDom.findDOMNode(this.refs.list);
- let index = this.props.selectedIndex - 2;
+ let index = this.props.selectedIndex - 1;
if (index < 0) {
index = 0;
}