|
1 | 1 | # jQuery.cuteScroll |
2 | 2 | Responsive jQuery y-axis scroll plugin that supports touches, swipes, mouse events. |
3 | | -Does not support overlapping elemens scrolling. |
| 3 | +Does not support overlapping elemens scrolling for now. |
4 | 4 |
|
5 | | -### Installation |
| 5 | +## Installation |
6 | 6 | ```html |
7 | 7 | <script src="jquery.cutescroll.min.js"></script> |
8 | 8 | ``` |
9 | | -### Configuration |
| 9 | + |
| 10 | +## Configuration |
10 | 11 | ```javascript |
11 | 12 | jQuery.cuteScroll.defaults={ |
12 | | - barColor:'black',// bar default color |
13 | | - barHeight:false,// if has a value, won't be dynamically changed |
14 | | - barWidth:false,// if empty, uses scrollerWidth |
15 | | - barMinHeight:'6rem', |
16 | | - barMaxHeight:'auto', |
17 | | - barOpacity:0.4, |
18 | | - barBorderRadius:'1rem', |
19 | | - barDraggable:true,// allows to drag the bar |
20 | | - barClass:'cuteScroll-bar', // default bar class |
21 | | - |
22 | | - railColor:'black',//rail default color |
23 | | - railWidth:false,// if not defined, uses scrollerWidth |
24 | | - railIndent:false,// if not defined, uses scrollerIndent |
25 | | - railOpacity:0.1, |
26 | | - railBorderRadius:'1rem', |
27 | | - railVisible:false,// Makes rail visible |
28 | | - railClass:'cuteScroll-rail',// default rail class |
29 | | - |
30 | | - scrollerIndent:'0.1rem',// scroller edge indent |
31 | | - scrollerPosition:'right',// side position -> scrollerPosition: right|left |
32 | | - scrollerWidth:'0.4rem', |
33 | | - scrollerAlwaysVisible:false,// if true, scroller becomes permanently visible |
34 | | - scrollerHideDelay:1000, |
35 | | - scrollerFadeOutSpeed:'slow', |
36 | | - scrollerFadeInSpeed:'fast', |
| 13 | + bar:{ |
| 14 | + // any css settings |
| 15 | + opacity:0.5, |
| 16 | + minHeight:'4rem', |
| 17 | + zIndex:110, |
| 18 | + ////// settings |
| 19 | + class:'cuteScroll-bar',//default class name |
| 20 | + }, |
| 21 | + rail:{ |
| 22 | + // any css settings |
| 23 | + opacity:0.1, |
| 24 | + height:'100%', |
| 25 | + zIndex:100, |
| 26 | + ////// settings |
| 27 | + visible:true,// Makes rail visible |
| 28 | + class:'cuteScroll-rail',//default class name |
| 29 | + }, |
| 30 | + scroller:{// bar and rail will get these values if have no own |
| 31 | + // any css settings |
| 32 | + background:'black', |
| 33 | + width:'0.5rem', |
| 34 | + right:0, |
| 35 | + ////// settings |
| 36 | + alwaysVisible:false,// if true, scroller becomes permanently visible |
| 37 | + hideDelay:1000, |
| 38 | + fadeOutSpeed:'slow', |
| 39 | + fadeInSpeed:'fast', |
| 40 | + }, |
| 41 | + canvas:{//scrollable element |
| 42 | + // any css settings |
| 43 | + class:'cuteScroll-canvas',//default class name |
| 44 | + }, |
| 45 | + wrapper:{ |
| 46 | + // any css settings |
| 47 | + class:'cuteScroll-wrapper',//default class name |
| 48 | + }, |
| 49 | + area:{// wrapper and canvas (scrollable element) will get these values if have no own |
| 50 | + // any css settings |
| 51 | + height:'20rem',// scrollable element height |
| 52 | + width:'100%',// scrollable element width |
| 53 | + }, |
| 54 | + mouse:{ |
| 55 | + pageScroll:true,// check if mousewheel should scroll the window if we reach top/bottom |
| 56 | + wheelStep:120,// scroll step for a wheel |
| 57 | + }, |
| 58 | + touch:{ |
| 59 | + moveFactor:1.1,// makes leaps faster (>1) or more slowly (<1) |
| 60 | + swipeStrengthFactor:1.25,// touch swipe strength coefficient |
| 61 | + swipeFadingFactor:0.075,// fading coefficient |
| 62 | + swipeVelocityThreshold:0.5,// touch movement velocity which is considered a swipe |
| 63 | + swipeDistanceThreshold:10,// touch movement distance to be considered a swipe |
| 64 | + swipeTimeAdjustmentThreshold:500,// recaltulates swipe parameters |
| 65 | + swipeIterationMinDistance:0.2,// min swipe iteration distance |
| 66 | + swipeIterationTimeout:5,// iteration timeout |
| 67 | + }, |
| 68 | + //element:{}, - you can change properties of every element you want |
| 69 | + on:{//related to events |
| 70 | + contentChange:false,// expects function which is called on content change -> onContentChange: <function> |
| 71 | + contentChangeShowScroller:true,// show scroller on content change if it is reasonable |
| 72 | + }, |
| 73 | + //priority:1,//defines overlapping priority, not supported for now |
| 74 | +}; |
| 75 | +``` |
37 | 76 |
|
38 | | - pageScroll:true,// check if mousewheel should scroll the window if we reach top/bottom |
39 | | - wheelStep:120,// scroll step for wheel |
| 77 | +## How To Use |
| 78 | +All confuguration commands should be passed included in a command object, as simple as this: |
| 79 | +```javascript |
| 80 | +jQuery.cuteScroll({ |
| 81 | + create:{// is the command object |
| 82 | + area:{ |
| 83 | + // any css settings |
| 84 | + width:'100vw', |
| 85 | + height:'100vh' |
| 86 | + }, |
| 87 | + element:{ |
| 88 | + body:{ |
| 89 | + // any css settings |
| 90 | + overflow:'hidden', |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | +}); |
| 95 | +``` |
40 | 96 |
|
41 | | - touchSwipeStrengthFactor:1.25,// touch swipe strength coefficient |
42 | | - touchSwipeFadingFactor:0.075,// fading coefficient |
43 | | - touchSwipeVelocityThreshold:0.5,// touch movement velocity which is considered a swipe |
44 | | - touchSwipeDistanceThreshold:10,// touch movement distance to be considered a swipe |
45 | | - touchSwipeTimeAdjustmentThreshold:500,// recaltulates swipe parameters |
46 | | - touchSwipeIterationMinDistance:0.2,// min swipe iteration distance |
47 | | - touchSwipeIterationTimeout:5,// iteration timeout |
48 | | - touchMoveFactor:1.1,// makes leaps faster (>1) or more slowly (<1) |
| 97 | +### Commands |
| 98 | +- create:<object> - creates a scroller |
| 99 | +- recreate:<object> - recreates a scroller |
| 100 | +- update:<object> - updates settings |
| 101 | +- jumpToTop:<boolean> - jumps to the top of a scrollable div if TRUE |
| 102 | +- jumpToBottom:<boolean> - jumps to the top of a scrollable div if TRUE |
| 103 | +- log:<string> - logs some message |
| 104 | +- alert:<string> - alerts some message |
| 105 | +- remove:<boolean> - removes a scroller if TRUE |
49 | 106 |
|
50 | | - height:'20rem',// scrollable element height |
51 | | - width:'100%',// scrollable element width |
52 | | - addClass:false,// adds classes to scrollable element on initialization -> addClass: <string> |
53 | | - removeClass:false,// removes classes of scrollable element on remove -> removeClass: <string> |
54 | | - addCss:false,// adds css on initialization |
55 | | - removeCss:false,// removes css on remove command, may use the same data as addCss |
| 107 | +### AddClass, removeClass |
| 108 | +You can add or remove any class of a scroller element. All changes will be reversed on the remove command |
| 109 | +```javascript |
| 110 | +jQuery.cuteScroll({ |
| 111 | + create:{// is the command object |
| 112 | + bar:{ |
| 113 | + // any css settings |
| 114 | + addClass:'newMyBarClass' |
| 115 | + removeClass:'formerMyBarClass' |
| 116 | + }, |
| 117 | + area:{ |
| 118 | + // any css settings |
| 119 | + width:'100vw', |
| 120 | + height:'100vh' |
| 121 | + }, |
| 122 | + } |
| 123 | +}); |
| 124 | +``` |
56 | 125 |
|
57 | | - wrapperClass:'cuteScroll-wrapper',// default wrapper class |
58 | | - //callbacks and related settings: |
59 | | - onContentChange:false,// expects function which is called on content change -> onContentChange: <function> |
60 | | - onContentChangeShow:true,// show scroller on content change if it is reasonable |
61 | | - //commands: |
62 | | - remove:false,// removes scroller, restores previous scrollable element style |
63 | | - jumpToTop:false,// jumps to the top of the scrollable element |
64 | | - jumpToBottom:false,// jumps to the bottom of the scrollable element |
65 | | - alert:false,// allerts a message -> alert: <string> |
66 | | -}; |
| 126 | +### Editing Other Elements |
| 127 | +You can also edit other elements properties by tag, class or id name or just change their css values. All changes will be reversed on the remove command |
| 128 | +```javascript |
| 129 | +jQuery.cuteScroll({ |
| 130 | + update:{// is the command object |
| 131 | + element:{ |
| 132 | + 'myElementClass':{ |
| 133 | + // any css settings |
| 134 | + height:'100rem', |
| 135 | + background:'red', |
| 136 | + addClass:'classNameToAdd' |
| 137 | + }, |
| 138 | + 'myOtherElementClass':{ |
| 139 | + // any css settings |
| 140 | + removeClass:'classNameToRemove' |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | +}); |
67 | 145 | ``` |
68 | | -### Demo |
69 | 146 |
|
| 147 | +## Demo |
70 | 148 | [Presentation of the index.html file](https://merrypanda.github.io/jQuery.cuteScroll) |
0 commit comments