Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 5961b3c

Browse files
davidpa9708David Perez Alvarez
authored andcommitted
refactor: update code, tests, tools, style, config
- add tsconfig and fix some strict errors - use parcel for development - remove bundle and demo - use jest for tests Signed-off-by: David Perez Alvarez <[email protected]>
1 parent 9769ac8 commit 5961b3c

31 files changed

+14222
-6009
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
.cache
2+
BrowserStackLocal
13
dist
4+
makefile
25
node_modules
3-
.cache
46
npm-debug.log
5-
BrowserStackLocal
7+
.vscode

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
.cache
2+
BrowserStackLocal
13
dist
4+
node_modules
5+
npm-debug.log
26
package-lock.json
37
package.json
48
tsconfig.json

.prettierrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"semi": true,
3-
"arrowParens": "always",
4-
"printWidth": 100,
52
"tabWidth": 2,
3+
"printWidth": 100,
4+
"semi": false,
5+
"singleQuote": false,
66
"trailingComma": "all"
77
}

.vscode/tasks.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,29 @@ The best utility package for smooth scrolling and centering elements in the page
3535
## Basic usage explanation
3636

3737
```js
38-
import { Scroll } from "scroll-utility";
38+
import { Scroll } from "scroll-utility"
3939

4040
// declare scroll manager instance
4141

42-
const scrollManager = new Scroll(); // create a scroll instance for window for scrolling the page
43-
const elementScrollManager = new Scroll(element); // for scrolling inside element instead of window
42+
const scrollManager = new Scroll() // create a scroll instance for window for scrolling the page
43+
const elementScrollManager = new Scroll(element) // for scrolling inside element instead of window
4444

4545
// start a scroll animation
46-
scrollManager.scrollBy(value, options); // offset current scroll position by "value"
47-
scrollManager.scrollToPosition(position, options); // scroll to position "position"
48-
scrollManager.scrollToPercent(percent, options); // scroll to position given by "percent"
49-
scrollManager.scrollToElement(element, options); // scroll to element "element"
46+
scrollManager.scrollBy(value, options) // offset current scroll position by "value"
47+
scrollManager.scrollToPosition(position, options) // scroll to position "position"
48+
scrollManager.scrollToPercent(percent, options) // scroll to position given by "percent"
49+
scrollManager.scrollToElement(element, options) // scroll to element "element"
5050

5151
// onScroll events
52-
scrollManager.onScroll = () => console.log("scroll ocurred in scrollManager container");
53-
scrollManager.onUtilityScroll = () => console.log("this scroll utility did scrolled");
54-
scrollManager.onUserScroll = () => console.log("this scroll utility did not scrolled!");
52+
scrollManager.onScroll = () => console.log("scroll ocurred in scrollManager container")
53+
scrollManager.onUtilityScroll = () => console.log("this scroll utility did scrolled")
54+
scrollManager.onUserScroll = () => console.log("this scroll utility did not scrolled!")
5555

5656
// stopping animations
5757

58-
scrollManager.stopAllAnimations(); // stop all animation in "scrollManager"
59-
const animation = scrollManager.scrollBy(10); // capture animation
60-
animation.stop(); // stop animation
58+
scrollManager.stopAllAnimations() // stop all animation in "scrollManager"
59+
const animation = scrollManager.scrollBy(10) // capture animation
60+
animation.stop() // stop animation
6161
```
6262

6363
## Installation
@@ -81,20 +81,20 @@ In this case `Scroll` will be a global variable as `ScrollUtility`
8181
#### Scroll inside window (default behavior)
8282

8383
```js
84-
import { Scroll } from "scroll-utility";
84+
import { Scroll } from "scroll-utility"
8585

86-
const windowScrollManager = new Scroll();
86+
const windowScrollManager = new Scroll()
8787
```
8888

8989
`windowScrollManager` will be used to scroll the normal overflow in webpages
9090

9191
#### Scroll a div or any other html element
9292

9393
```js
94-
import { Scroll } from "scroll-utility";
94+
import { Scroll } from "scroll-utility"
9595

96-
const htmlElement = document.getElementById("some-html-element");
97-
const elementScrollManager = new Scroll(htmlElement);
96+
const htmlElement = document.getElementById("some-html-element")
97+
const elementScrollManager = new Scroll(htmlElement)
9898
```
9999

100100
`elementScrollManager` will be used to scroll inside that specific element.
@@ -106,35 +106,35 @@ If `htmlElement` is _null_ or _undefined_ it will fallback to window scroll by d
106106

107107
```js
108108
// asuming windowScrollManager is declared
109-
windowScrollManager.scroll.toPosition(number, options); // number is a position in (px) in scroll
109+
windowScrollManager.scroll.toPosition(number, options) // number is a position in (px) in scroll
110110

111111
// example:
112-
windowScrollManager.scroll.toPosition(273);
112+
windowScrollManager.scroll.toPosition(273)
113113
```
114114

115115
#### Scroll to a percent
116116

117117
```js
118-
windowScrollManager.scroll.toPercent(percent, options); // number is a percent(from 0 to 100)
118+
windowScrollManager.scroll.toPercent(percent, options) // number is a percent(from 0 to 100)
119119

120120
// example:
121-
windowScrollManager.scroll.toPercent(0); // scroll to the begining of the page
122-
windowScrollManager.scroll.toPercent(50); // to the middle
123-
windowScrollManager.scroll.toPercent(100); // the end
121+
windowScrollManager.scroll.toPercent(0) // scroll to the begining of the page
122+
windowScrollManager.scroll.toPercent(50) // to the middle
123+
windowScrollManager.scroll.toPercent(100) // the end
124124
```
125125

126126
#### Scroll to an element
127127

128128
```js
129-
windowScrollManager.scroll.toElement(htmlElement, options);
129+
windowScrollManager.scroll.toElement(htmlElement, options)
130130
```
131131

132132
Here `htmlElement` should be an html element. _null_ or _undefined_ will scroll to the start of its _scrollManger_ container
133133

134134
#### Offset scroll position
135135

136136
```js
137-
windowScrollManager.scrollBy(number, options); // will offset scroll position, can be negative
137+
windowScrollManager.scrollBy(number, options) // will offset scroll position, can be negative
138138
```
139139

140140
#### options
@@ -144,61 +144,63 @@ const optionsDefault = {
144144
duration: 0, // duration of the scroll
145145
horizontal: false, // direction of the scroll animation
146146
center: 0, // this value is used only for scrollToElement
147-
};
147+
}
148148
```
149149

150150
#### examples
151151

152152
```js
153153
windowScrollManager.scroll.toPercent(50, {
154154
duration: 1000, // will scroll to the middle of the page vertically
155-
});
155+
})
156156

157157
windowScrollManager.scroll.toPosition(50, {
158158
horizontal: true, // will scroll instantly to the middle of the page horizontally in 1 sec
159-
});
159+
})
160160

161161
windowScrollManager.scroll.toElement(htmlElement, {
162162
horizontally: true,
163163
duration: 1500,
164164
center: 50, // will scroll to the element and center it at 50% in the view (or its container)
165-
});
165+
})
166166
```
167167

168168
### Stop animations
169169

170170
```js
171-
windowScrollManager.stopAllAnimations(); // this will stop all animations in windowScrollManager
171+
windowScrollManager.stopAllAnimations() // this will stop all animations in windowScrollManager
172172

173173
// to stop specific animations, you'll have to capture them first:
174-
const animation = windowScrollManager.scroll.toPercent(50, { duration: 1000 });
174+
const animation = windowScrollManager.scroll.toPercent(50, { duration: 1000 })
175175

176-
animation.stop();
176+
animation.stop()
177177
```
178178

179179
### Change animation function
180180

181181
```js
182-
windowScrollManager.easing = some_easing_function; // will change default easing function for next created animations
182+
windowScrollManager.easing = some_easing_function // will change default easing function for next created animations
183183

184184
// or just for one animation:
185-
windowScrollManager.scroll.toPercent(50, { duration: 1000 }).easing = some_easing_function;
185+
windowScrollManager.scroll.toPercent(50, {
186+
duration: 1000,
187+
}).easing = some_easing_function
186188
```
187189

188190
### onScroll events
189191

190192
```js
191-
const scrollManager = new Scroll(some_element);
193+
const scrollManager = new Scroll(some_element)
192194

193-
scrollManager.onScroll = () => console.log("scroll ocurred in scrollManager container");
194-
scrollManager.onUtilityScroll = () => console.log("this scroll utility did scrolled");
195-
scrollManager.onUserScroll = () => console.log("this scroll utility did not scrolled!");
195+
scrollManager.onScroll = () => console.log("scroll ocurred in scrollManager container")
196+
scrollManager.onUtilityScroll = () => console.log("this scroll utility did scrolled")
197+
scrollManager.onUserScroll = () => console.log("this scroll utility did not scrolled!")
196198
```
197199

198200
for example, if you wish to stop animation on user scroll you could do:
199201

200202
```js
201-
scrollManager.onUserScroll = () => scrollManager.stopAllAnimations();
203+
scrollManager.onUserScroll = () => scrollManager.stopAllAnimations()
202204
```
203205

204206
### Stack animations and high precision
@@ -210,16 +212,16 @@ That is the best thing of scroll-utility. It is design to work with multiple ani
210212
For example:
211213

212214
```js
213-
scrollManager.scrollBy(500, { duration: 1000 });
214-
scrollManager.scrollBy(34, { duration: 775 });
215+
scrollManager.scrollBy(500, { duration: 1000 })
216+
scrollManager.scrollBy(34, { duration: 775 })
215217
```
216218

217219
1 second from it started to move, it will have been offset its position for 534px
218220

219221
```js
220-
scrollManager.scroll.toPosition(0);
221-
scrollManager.scroll.toPercent(50, { duration: 500 });
222-
scrollManager.scroll.toPercent(50, { duration: 1000 });
222+
scrollManager.scroll.toPosition(0)
223+
scrollManager.scroll.toPercent(50, { duration: 500 })
224+
scrollManager.scroll.toPercent(50, { duration: 1000 })
223225
```
224226

225227
in this example in 1 second to scroll bar will be at the end, due that it created 2 scroll animations that were to scroll 50% of the page (from 0 to 50), so 50% + 50% = 100%

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
testMatch: [
5+
"**/test/automate/index.ts",
6+
]
7+
}

0 commit comments

Comments
 (0)