@glitchr/stickyjs 1.0.43 → 1.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/js/sticky.js +16 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glitchr/stickyjs",
3
- "version": "1.0.43",
3
+ "version": "1.0.50",
4
4
  "description": "Sticky scroll library",
5
5
  "main": "src/index.js",
6
6
  "repository": {
package/src/js/sticky.js CHANGED
@@ -677,7 +677,20 @@ $.fn.serializeObject = function () {
677
677
  return parseInt(closest);
678
678
  }
679
679
 
680
- Sticky.userScroll = function(el = undefined) { return $(el === undefined ? document.documentElement : el).closestScrollable().prop("user-scroll") ?? true; }
680
+ Sticky.userScroll = function(el = undefined) {
681
+ // Defensive: closestScrollable() can return a value without .prop in
682
+ // some race conditions (transient DOM during transparent.js page
683
+ // transitions, sticky-scrollpercent triggers fired against detached
684
+ // nodes). Default to true so the autoscroll falls back to "user is
685
+ // scrolling, don't auto-advance."
686
+ try {
687
+ var $target = $(el === undefined ? document.documentElement : el);
688
+ if (!$target || !$target.length) return true;
689
+ var $scroll = $target.closestScrollable && $target.closestScrollable();
690
+ if (!$scroll || typeof $scroll.prop !== "function") return true;
691
+ return $scroll.prop("user-scroll") ?? true;
692
+ } catch (e) { return true; }
693
+ }
681
694
  Sticky.scrollTo = function(dict, callback = function() {}, el = window)
682
695
  {
683
696
  el = $(el).length ? $(el)[0] : window;
@@ -707,6 +720,8 @@ $.fn.serializeObject = function () {
707
720
 
708
721
  if(speed) {
709
722
 
723
+ var distanceX = 0, distanceY = 0;
724
+
710
725
  var currentScrollX = $(el)[0].scrollLeft;
711
726
  if(currentScrollX < scrollLeft || scrollLeft == 0) // Going to the right
712
727
  distanceX = Math.abs(scrollLeft - currentScrollX);