Skip to content

Commit 439e8e5

Browse files
committed
fix typo, update maxScrollAmount continuously
1 parent 8bdc9c2 commit 439e8e5

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# jquery-scroll-direction-plugin
1+
# Scroll Direction 1.0.1
22
A lightweight jQuery plugin to detect scroll direction.
33

44
**[View the Demo on CodePen →](https://codepen.io/phucbui/pen/yLaeqBw)**
55

66
## Getting started
77

8-
### 1. Include Scroll Direction Plugin to your site.
8+
### 1. Include Scroll Direction to your site.
99

1010
**Direct Download**
1111

@@ -17,14 +17,14 @@ You can [download the plugin directly from Github](https://raw.githubusercontent
1717

1818
**CDN** [![](https://data.jsdelivr.com/v1/package/gh/phucbm/jquery-scroll-direction-plugin/badge)](https://www.jsdelivr.com/package/gh/phucbm/jquery-scroll-direction-plugin)
1919

20-
You can also browse for the latest version by visiting [Scroll Direction Plugin on jsDelivr](https://cdn.jsdelivr.net/gh/phucbm/jquery-scroll-direction-plugin/)
20+
You can also browse for the latest version by visiting [Scroll Direction on jsDelivr](https://cdn.jsdelivr.net/gh/phucbm/jquery-scroll-direction-plugin/)
2121

2222
```html
23-
<!-- Scroll Direction Plugin - v1.0.0 -->
24-
<script src="https://cdn.jsdelivr.net/gh/phucbm/jquery-scroll-direction-plugin@1.0.0/jquery.scroll-direction.js"></script>
23+
<!-- Scroll Direction - v1.0.1 -->
24+
<script src="https://cdn.jsdelivr.net/gh/phucbm/jquery-scroll-direction-plugin@1.0.1/jquery.scroll-direction.js"></script>
2525

26-
<!-- Scroll Direction Plugin - v1.0.0 - minified -->
27-
<script src="https://cdn.jsdelivr.net/gh/phucbm/jquery-scroll-direction-plugin@1.0.0/jquery.scroll-direction.min.js"></script>
26+
<!-- Scroll Direction - v1.0.1 - minified -->
27+
<script src="https://cdn.jsdelivr.net/gh/phucbm/jquery-scroll-direction-plugin@1.0.1/jquery.scroll-direction.min.js"></script>
2828
```
2929

3030
### 2. Initialize Scroll Direction
@@ -40,7 +40,7 @@ $.scrollDirection.init();
4040

4141
### 1. Methods
4242

43-
#### $.scrollDirection.init()
43+
- `$.scrollDirection.init()`
4444

4545
```js
4646
// init Scroll Direction with full settings

jquery.scroll-direction.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* jQuery Scroll Direction Plugin 1.0.0
2+
* jQuery Scroll Direction Plugin 1.0.1
33
* https://github.com/phucbm/jquery-scroll-direction-plugin
44
*
55
* MIT License | Copyright (c) 2020 Minh-Phuc Bui
@@ -27,7 +27,6 @@
2727
// Method: init()
2828
obj.init = function (options) {
2929
pluginActive = true;
30-
// update settings
3130
settings = $.extend(settings, options);
3231
};
3332

@@ -80,43 +79,44 @@
8079

8180
// Main process
8281
let $w = $(window),
83-
lasScrollAmount = false,
82+
lastScrollAmount = false,
8483
scrollAmount = $w.scrollTop(),
8584
maxScrollAmount = $(document).height() - $w.height();
8685
$w.on("load scroll resize", function () {
8786
if (pluginActive) {
8887
// update values
8988
scrollAmount = $w.scrollTop();
89+
maxScrollAmount = $(document).height() - $w.height();
9090

9191
// check scroll directions
92-
if (scrollAmount > lasScrollAmount && lasScrollAmount >= 0) {
92+
if (scrollAmount > lastScrollAmount && lastScrollAmount >= 0) {
9393
// scroll down
9494
obj.isScrollUp = false;
9595
obj.isScrollDown = true;
9696

9797
$w.trigger(scrollDown);
98-
} else if (scrollAmount < lasScrollAmount && lasScrollAmount >= 0) {
98+
} else if (scrollAmount < lastScrollAmount && lastScrollAmount >= 0) {
9999
// scroll up
100100
obj.isScrollUp = true;
101101
obj.isScrollDown = false;
102102

103103
$w.trigger(scrollUp);
104104
} else if (scrollAmount < 0) {
105-
// elastic scroll: negative value
105+
// scroll up (elastic scroll with negative value)
106106
obj.isScrollUp = true;
107107
obj.isScrollDown = false;
108108

109109
$w.trigger(scrollUp);
110110
} else if (scrollAmount > maxScrollAmount) {
111-
// elastic scroll: position value
111+
// scroll down (elastic scroll with positive value)
112112
obj.isScrollUp = false;
113113
obj.isScrollDown = true;
114114

115115
$w.trigger(scrollDown);
116116
}
117117

118118
// update the last position
119-
lasScrollAmount = scrollAmount;
119+
lastScrollAmount = scrollAmount;
120120

121121
// check scroll positions
122122
if (scrollAmount <= settings.topOffset) {

0 commit comments

Comments
 (0)