137 |
138 | {this.props.children}
139 |
140 | {scrollbarY}
141 | {scrollbarX}
142 |
143 | );
144 | }
145 | }
146 |
147 | Scrollable.propTypes = {
148 | className: React.PropTypes.string,
149 | speed: React.PropTypes.number,
150 | contentClassName: React.PropTypes.string,
151 | vertical: React.PropTypes.bool,
152 | horizontal: React.PropTypes.bool
153 | };
154 |
155 | Scrollable.defaultProps = {
156 | speed: 1,
157 | vertical: true,
158 | horizontal: true,
159 | useCssTransform: true
160 | };
161 |
162 | export default Scrollable;
163 |
--------------------------------------------------------------------------------
/src/js/scrollable.js:
--------------------------------------------------------------------------------
1 | import scrollTouch from './scrollTouch.js';
2 | import scrollMouse from './scrollMouse.js';
3 |
4 | function isTouch() {
5 | return 'ontouchstart' in window || 'onmsgesturechange' in window;
6 | }
7 |
8 | export default isTouch() ? scrollTouch : scrollMouse;
--------------------------------------------------------------------------------
/src/less/scrollbar.less:
--------------------------------------------------------------------------------
1 | .scrollarea-content {
2 | margin: 0;
3 | padding: 0;
4 | overflow: hidden;
5 | position: relative;
6 | }
7 |
8 | .scrollarea {
9 | position: relative;
10 | overflow: hidden;
11 | .scrollbar-container {
12 |
13 | .scrollbar {
14 | border-radius: 10px;
15 | }
16 |
17 | &.horizontal {
18 | width: 100%;
19 | height: 10px;
20 | left: 0;
21 | bottom: 5px;
22 |
23 | .scrollbar {
24 | height: 100%;
25 | height: 8px;
26 | background: black;
27 | margin-top: 1px;
28 | }
29 | }
30 |
31 | &.vertical {
32 | width: 10px;
33 | height: 100%;
34 | right: 5px;
35 | top: 0;
36 |
37 | .scrollbar {
38 | width: 100%;
39 | height: 20px;
40 | background: black;
41 | margin-left: 1px;
42 | }
43 | }
44 |
45 | position: absolute;
46 | background: none;
47 | opacity: 0;
48 | z-index: 9999;
49 |
50 | -webkit-transition: all .4s;
51 | -moz-transition: all .4s;
52 | -ms-transition: all .4s;
53 | -o-transition: all .4s;
54 | transition: all .4s;
55 |
56 | &:hover, &.active {
57 | opacity: .4 !important;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/less/site.less:
--------------------------------------------------------------------------------
1 | html, body, #main {
2 | height: 100%;
3 | }
4 |
5 | body {
6 | margin: 0;
7 |
8 | h1, h2, h3, h4, h5, h6 {
9 | font-weight: normal;
10 | }
11 |
12 | .container {
13 | width: 100%;
14 | height: 100%;
15 | position: relative;
16 | }
17 |
18 | .content {
19 | width: 300px;
20 | height: 300px;
21 | background: #5fe151;
22 | overflow: hidden;
23 | position: relative;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | var webpack = require('webpack');
2 | var path = require('path');
3 | module.exports = {
4 | entry: {
5 | example: './example/js/main.js',
6 | main: ['./scrollable.js'],
7 | vendor: ['react']
8 | },
9 | output: {
10 | filename: '[name].js'
11 | },
12 | resolve: {
13 | alias: {
14 | 'react': 'react/dist/react-with-addons.min'
15 | },
16 | modulesDirectories: ['node_modules', 'bower_components'],
17 | },
18 | plugins: [
19 | new webpack.optimize.CommonsChunkPlugin(
20 | {
21 | name: ['vendor']
22 | }
23 | )
24 | ],
25 | module: {
26 | loaders: [
27 | {
28 | test: /\.js|\.jsx$/,
29 | exclude: /node_modules|bower_components/,
30 | loader: 'babel-loader'
31 | }, {
32 | test: /\.less$/,
33 | loader: 'css?sourceMap!less?sourceMap'
34 | }
35 | ]
36 | }
37 | };
38 |
--------------------------------------------------------------------------------