25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

README.md 3.9 KiB

3 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # react-smooth-scrollbar
  2. [smooth-scrollbar](https://github.com/idiotWu/smooth-scrollbar) for react projects.
  3. ## Requirements
  4. React 0.14+
  5. ## Install
  6. ```
  7. npm install react-smooth-scrollbar smooth-scrollbar --save
  8. ```
  9. ## Demo
  10. [http://idiotwu.github.io/react-smooth-scrollbar/](http://idiotwu.github.io/react-smooth-scrollbar/)
  11. ## Usage
  12. ```js
  13. import React from 'react';
  14. import ReactDOM from 'react-dom';
  15. import Scrollbar from 'react-smooth-scrollbar';
  16. class App extends React.Component {
  17. render() {
  18. return (
  19. <Scrollbar
  20. damping={number},
  21. thumbMinSize={number},
  22. syncCallbacks={boolean},
  23. renderByPixels={boolean},
  24. alwaysShowTracks={boolean},
  25. continuousScrolling={boolean},
  26. wheelEventTarget={element},
  27. plugins={object},
  28. onScroll={func},
  29. >
  30. your contents here...
  31. </Scrollbar>
  32. );
  33. }
  34. }
  35. ReactDOM.render(<App />, document.body);
  36. ```
  37. ### Available Options
  38. | parameter | type | default | description |
  39. | :--------: | :--: | :-----: | :---------- |
  40. | damping | `number` | `0.1` | Momentum reduction damping factor, a float value between `(0, 1)`. The lower the value is, the more smooth the scrolling will be (also the more paint frames). |
  41. | thumbMinSize | `number` | `20` | Minimal size for scrollbar thumbs. |
  42. | renderByPixels | `boolean` | `true` | Render every frame in integer pixel values, set to `true` to improve scrolling performance. |
  43. | alwaysShowTracks | `boolean` | `false` | Keep scrollbar tracks visible. |
  44. | continuousScrolling | `boolean` | `true` | Set to `true` to allow outer scrollbars continue scrolling when current scrollbar reaches edge. |
  45. | wheelEventTarget | `EventTarget` | `null` | Element to be used as a listener for mouse wheel scroll events. By default, the container element is used. This option will be useful for dealing with fixed elements. |
  46. | plugins | `object` | `{}` | Options for plugins, see [Plugin System](https://github.com/idiotWu/smooth-scrollbar/blob/master/docs/plugin.md). |
  47. **Confusing with the option field? Try edit tool [here](http://idiotwu.github.io/smooth-scrollbar/)!**
  48. ## Using Scrollbar Plugins
  49. ```js
  50. import { Component } from 'react';
  51. import PropTypes from 'prop-types';
  52. import SmoothScrollbar from 'smooth-scrollbar';
  53. import OverscrollPlugin from 'smooth-scrollbar/plugins/overflow';
  54. import Scrollbar from 'react-smooth-scrollbar';
  55. SmoothScrollbar.use(OverscrollPlugin);
  56. class App2 extends Component {
  57. render() {
  58. return (
  59. <Scrollbar> ... </Scrollbar>
  60. );
  61. }
  62. }
  63. ```
  64. ## Get Scrollbar Instance
  65. 1. Use `ref` in **parent component**:
  66. ```javascript
  67. class Parent extends React.Component {
  68. componentDidMount() {
  69. const { scrollbar } = this.$container;
  70. }
  71. render() {
  72. return (
  73. <Scrollbar ref={c => this.$container = c}>
  74. your content...
  75. </Scrollbar>
  76. );
  77. }
  78. }
  79. ```
  80. 2. Use `Context` in **child component**:
  81. ```javascript
  82. class Child extends React.Component {
  83. static contextTypes = {
  84. getScrollbar: React.PropTypes.func
  85. };
  86. componentDidMount() {
  87. this.context.getScrollbar((scrollbar) => {
  88. // ...
  89. });
  90. }
  91. render() {
  92. return <div> this is child component. </div>;
  93. }
  94. }
  95. class App extends React.Component {
  96. render(){
  97. return (
  98. <Scrollbar>
  99. <Child />
  100. </Scrollbar>
  101. );
  102. }
  103. }
  104. ```
  105. ## APIs
  106. [Documents](https://github.com/idiotWu/smooth-scrollbar/docs)
  107. ## License
  108. MIT.
  109. [![Sponsor](https://app.codesponsor.io/embed/haJ2RqCqwBLZtPKnMNBYgn4M/idiotWu/react-smooth-scrollbar.svg)](https://app.codesponsor.io/link/haJ2RqCqwBLZtPKnMNBYgn4M/idiotWu/react-smooth-scrollbar)