{"id":19204508,"url":"https://github.com/hyy1115/react-roll-container","last_synced_at":"2025-05-12T15:46:23.131Z","repository":{"id":57343715,"uuid":"116234699","full_name":"hyy1115/react-roll-container","owner":"hyy1115","description":"为了解决移动端body中有多层滚动重叠导致的卡顿和点击穿透问题而封装的React滚动组件","archived":false,"fork":false,"pushed_at":"2018-08-23T05:49:46.000Z","size":8,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T18:05:58.408Z","etag":null,"topics":["iscroll","javascript","jroll","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyy1115.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-04T08:25:58.000Z","updated_at":"2023-03-10T09:06:52.000Z","dependencies_parsed_at":"2022-09-12T06:30:36.310Z","dependency_job_id":null,"html_url":"https://github.com/hyy1115/react-roll-container","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyy1115%2Freact-roll-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyy1115%2Freact-roll-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyy1115%2Freact-roll-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyy1115%2Freact-roll-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyy1115","download_url":"https://codeload.github.com/hyy1115/react-roll-container/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253767727,"owners_count":21961166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iscroll","javascript","jroll","react"],"created_at":"2024-11-09T13:08:30.145Z","updated_at":"2025-05-12T15:46:23.106Z","avatar_url":"https://github.com/hyy1115.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-roll-container\n\n采用比IScroll更加轻量的JRoll封装的React组件，可以作为移动端DOM内部CSS3滚动的组件。\n\n它是为了解决移动端body中有多层滚动重叠导致的卡顿和点击穿透问题，比如支付宝app里面的饿了么网站，就存在双层滚动时候的穿透问题。\n\n常用在以下地方：\n\n1、弹框内部的滚动\n\n2、多列表的滚动\n\n3、类似京东移动端垂直固定导航的滚动: https://so.m.jd.com/category/all.html\n\n4、其他可能的场景\n\n### 安装\n\n```npm\nnpm i --save react-roll-container\n```\n\n### 用法\n\n1、整个页面采用CSS3垂直滚动\n```javascript\nimport MyJRoll from 'react-roll-container'\n\nclass Component extends React.Component {\n    state = {\n        height: '100vh'\n    }\n    render() {\n        const { height } = this.state\n        return (\n            \u003cMyJRoll height={height + 'px'}\u003e\n                {/*子组件*/}\n            \u003c/MyJRoll\u003e\n        )\n    }\n}\n```\n\n2、组件内部的子组件采用CSS3垂直滚动\n```javascript\nimport MyJRoll from 'react-roll-container'\n\nclass Component extends React.Component {\n    state = {\n        height: 0\n    }\n    componentDidMount() {\n        this.getScrollHeight()\n    }\n    getScrollHeight = () =\u003e {\n        //主要是求出滚动区域的实际高度，如果已知实际高度是个固定值，则不需要设置state\n        //如果实际高度需要根据一些特定的加减法求出来的，则通过state设置\n        \n        //例如：\n        const header = document.querySelector('.header')\n        this.setState(() =\u003e ({height: getClientHeight - header.offsetHeight}))\n    }\n    render() {\n        const { height } = this.state\n        return (\n            \u003cdiv\u003e\n                \u003cHeader\u003e\n                    头部信息\n                \u003c/Header\u003e\n                \u003cMyJRoll height={height + 'px'}\u003e\n                    \u003cNavList /\u003e         \n                \u003c/MyJRoll\u003e\n            \u003c/div\u003e\n        )\n    }\n}\n```\n3、弹框组件采用CSS3垂直滚动\n\n我们知道，在移动端做弹框内部的滚动的时候，会有点击穿透问题，如果采用MyJRoll组件来包装弹框，则不会有这个问题\n\n4、更多使用场景需自行发现\n\n### 可配置信息\n\nheight：这个是最重要的配置，因为浏览器需要知道你的滚动区域的实际高度，有时候js执行后计算高度不准确，可能是因为你的DOM还没有渲染完成，就像使用JQuery的时候要ready才能保证安全\n\nmaxHeight：通常你不需要管它\n\nbgColor：用来设置滚动区域的背景色，默认是 '#f6f6f6'","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyy1115%2Freact-roll-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyy1115%2Freact-roll-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyy1115%2Freact-roll-container/lists"}