Skip to content

Commit 0ae9c24

Browse files
committed
♻️ change load scroll resize events
1 parent 8213d3f commit 0ae9c24

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

jquery.scroll-direction.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
bottomOffset: () => 0,
1818
atBottomIsAtMiddle: true,
1919
indicator: true,
20-
indicatorElement: $("body"),
20+
indicatorElement: document.querySelector('body'),
2121
scrollUpClass: "scroll-up",
2222
scrollDownClass: "scroll-down",
2323
scrollAtTopClass: "scroll-top",
@@ -87,16 +87,16 @@
8787

8888
for(i; i < l; i++){
8989
if(indicators.values[i]){
90-
settings.indicatorElement.addClass(indicators.classes[i]);
90+
settings.indicatorElement.classList.add(indicators.classes[i]);
9191
}else{
92-
settings.indicatorElement.removeClass(indicators.classes[i]);
92+
settings.indicatorElement.classList.remove(indicators.classes[i]);
9393
}
9494
}
9595
}
9696
}
9797

9898
// update
99-
function update(){
99+
function update(e){
100100
if(pluginActive){
101101
// check scroll directions
102102
if(settings.scrollAmount() > lastScrollAmount && lastScrollAmount >= 0){
@@ -179,14 +179,18 @@
179179

180180
// update on window events
181181
if(!settings.hijacking){
182-
$w.on("load scroll resize", function(){
183-
// update values
184-
update();
185-
});
182+
window.addEventListener('load', e => update(e));
183+
window.addEventListener('scroll', e => update(e));
184+
window.addEventListener('resize', e => update(e));
186185
}
187186

187+
// for manual, jQuery-free
188+
window.scrollDirection = obj;
189+
188190
// Only assign to jQuery.scrollDirection if jQuery is loaded
189191
if(jQuery){
190-
jQuery.scrollDirection = obj;
192+
jQuery.scrollDirection = window.scrollDirection;
191193
}
194+
195+
return window.scrollDirection;
192196
})(jQuery);

0 commit comments

Comments
 (0)