|
1 | 1 | /** |
2 | | - * jQuery Scroll Direction Plugin 1.0.0 |
| 2 | + * jQuery Scroll Direction Plugin 1.0.1 |
3 | 3 | * https://github.com/phucbm/jquery-scroll-direction-plugin |
4 | 4 | * |
5 | 5 | * MIT License | Copyright (c) 2020 Minh-Phuc Bui |
|
27 | 27 | // Method: init() |
28 | 28 | obj.init = function (options) { |
29 | 29 | pluginActive = true; |
30 | | - // update settings |
31 | 30 | settings = $.extend(settings, options); |
32 | 31 | }; |
33 | 32 |
|
|
80 | 79 |
|
81 | 80 | // Main process |
82 | 81 | let $w = $(window), |
83 | | - lasScrollAmount = false, |
| 82 | + lastScrollAmount = false, |
84 | 83 | scrollAmount = $w.scrollTop(), |
85 | 84 | maxScrollAmount = $(document).height() - $w.height(); |
86 | 85 | $w.on("load scroll resize", function () { |
87 | 86 | if (pluginActive) { |
88 | 87 | // update values |
89 | 88 | scrollAmount = $w.scrollTop(); |
| 89 | + maxScrollAmount = $(document).height() - $w.height(); |
90 | 90 |
|
91 | 91 | // check scroll directions |
92 | | - if (scrollAmount > lasScrollAmount && lasScrollAmount >= 0) { |
| 92 | + if (scrollAmount > lastScrollAmount && lastScrollAmount >= 0) { |
93 | 93 | // scroll down |
94 | 94 | obj.isScrollUp = false; |
95 | 95 | obj.isScrollDown = true; |
96 | 96 |
|
97 | 97 | $w.trigger(scrollDown); |
98 | | - } else if (scrollAmount < lasScrollAmount && lasScrollAmount >= 0) { |
| 98 | + } else if (scrollAmount < lastScrollAmount && lastScrollAmount >= 0) { |
99 | 99 | // scroll up |
100 | 100 | obj.isScrollUp = true; |
101 | 101 | obj.isScrollDown = false; |
102 | 102 |
|
103 | 103 | $w.trigger(scrollUp); |
104 | 104 | } else if (scrollAmount < 0) { |
105 | | - // elastic scroll: negative value |
| 105 | + // scroll up (elastic scroll with negative value) |
106 | 106 | obj.isScrollUp = true; |
107 | 107 | obj.isScrollDown = false; |
108 | 108 |
|
109 | 109 | $w.trigger(scrollUp); |
110 | 110 | } else if (scrollAmount > maxScrollAmount) { |
111 | | - // elastic scroll: position value |
| 111 | + // scroll down (elastic scroll with positive value) |
112 | 112 | obj.isScrollUp = false; |
113 | 113 | obj.isScrollDown = true; |
114 | 114 |
|
115 | 115 | $w.trigger(scrollDown); |
116 | 116 | } |
117 | 117 |
|
118 | 118 | // update the last position |
119 | | - lasScrollAmount = scrollAmount; |
| 119 | + lastScrollAmount = scrollAmount; |
120 | 120 |
|
121 | 121 | // check scroll positions |
122 | 122 | if (scrollAmount <= settings.topOffset) { |
|
0 commit comments