【问题标题】:React.js and horizontal IScroll 5 with dynamic widthReact.js 和具有动态宽度的水平 IScroll 5
【发布时间】:2015-03-21 06:52:05
【问题描述】:

我无法让 IScroll 与 React.js 一起使用。

var SubHeaderMenu = React.createClass({
getDefaultProps: function () {
    return {items: []};
},

componentDidMount: function () {
    if (this.props.items.length && this.isMounted()) {
        this.scroll = new IScroll(this.getDOMNode(), {
            scrollX: true,
            scrollY: false,
            mouseWheel: true,
        });
    }
},

render: function () {
    var itemNodes = this.props.items.map(function (item) {
        return <div key={item.name} className="subheader-item">{item.name}</div>;
    }.bind(this));

    return (
        <div className="bar bar-standard bar-header-secondary subheader">
            <div className="scroller" ref="scroller">
                <div className="scroller-inner" ref="scrollerInner">{itemNodes}</div>
            </div>
        </div>
    );
}
});

SubHeaderMenu 组件接收项目列表作为道具。如果我在 CSS 中为 .scroller 设置宽度,这很好用:

.scroller { width: 600px; ... }

但在 CSS 中没有宽度,它不会滚动..

如何处理每个列表项的动态宽度?

【问题讨论】:

    标签: javascript css reactjs iscroll react-jsx


    【解决方案1】:

    有一个用于 react 和 IScroll 的 npm-package:

    https://www.npmjs.com/package/react-iscroll

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-09
      • 1970-01-01
      • 2021-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多