@glitchr/stickyjs 1.0.21 → 1.0.23

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 +59 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glitchr/stickyjs",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "Sticky scroll library",
5
5
  "main": "src/index.js",
6
6
  "repository": {
package/src/js/sticky.js CHANGED
@@ -191,7 +191,7 @@ $.fn.serializeObject = function () {
191
191
  // Time control
192
192
  "tick" : "1ms" ,
193
193
  "debounce": "500ms" ,
194
- "threshold": "4000ms",
194
+ "threshold": "5000ms",
195
195
 
196
196
  "scrollcatch": false,
197
197
  "scrolllock" : true,
@@ -213,6 +213,10 @@ $.fn.serializeObject = function () {
213
213
  "scrollsnap_start" : "start", //start, center, end
214
214
  "scrollsnap_proximity" : 0.01 ,
215
215
 
216
+ "swipe" : true,
217
+ "swipe_timegate" : "1s",
218
+ "swipe_threshold" : 200,
219
+
216
220
  "swipehint" : true,
217
221
  "swipehint_delay" : "1s",
218
222
  "swipehint_debounce" : 0,
@@ -872,6 +876,56 @@ $.fn.serializeObject = function () {
872
876
  return current < magnets.length-1 ? magnets[current+1] : magnets[current];
873
877
  }
874
878
 
879
+
880
+ Sticky.onSwipe = function (el = window) {
881
+
882
+ var t0 = 0, x0 = 0, y0 = 0;
883
+
884
+ function handleSwipe(that, swipeDirection) {
885
+
886
+ if (swipeDirection > 0) {
887
+
888
+ if(debug) console.log("Swipe right in ", that)
889
+ that.dispatchEvent("sticky.swipe_right");
890
+
891
+ } else if (swipeDirection < 0) {
892
+
893
+ if(debug) console.log("Swipe left in ", that);
894
+ that.dispatchEvent("sticky.swipe_left");
895
+ }
896
+ };
897
+
898
+ window.addEventListener('touchstart', function (e) {
899
+
900
+ var touchobj = e.changedTouches[0]
901
+
902
+ t0 = new Date().getTime() // record time when finger first makes contact with surface
903
+ x0 = touchobj.pageX;
904
+ y0 = touchobj.pageY;
905
+
906
+ }, false);
907
+
908
+ window.addEventListener('touchend', function (e) {
909
+
910
+ var touchobj = e.changedTouches[0]
911
+ var dX = touchobj.pageX - x0 // get total dist traveled by finger while in contact with surface
912
+ var dT = new Date().getTime() - t0 // get time elapsed
913
+
914
+ var trigger = (dT <= parseInt(Sticky.get("swipe_timegate")) && Math.abs(touchobj.pageY - y0) <= 100);
915
+
916
+ var swipeDirection = 0;
917
+ if(trigger) swipeDirection = Math.abs(dX) >= parseInt(Sticky.get("swipe_threshold")) ? (dX > 0 ? 1 : -1) : 0;
918
+
919
+ $(el).each(function() {
920
+
921
+ if(this === e.target || this.contains(e.target))
922
+ handleSwipe(this, swipeDirection);
923
+ });
924
+
925
+ }, false);
926
+ }
927
+
928
+
875
929
  var trigger = {};
876
930
  Sticky.onScrollPercent = function(e)
877
931
  {
@@ -1555,6 +1609,9 @@ $.fn.serializeObject = function () {
1555
1609
  anchorY = anchorElem.length ? anchorElem[0].offsetTop - Sticky.getScrollPadding().top : 0;
1556
1610
  });
1557
1611
 
1612
+ if(Sticky.get("swipe"))
1613
+ Sticky.onSwipe($(".sticky-swipe"));
1614
+
1558
1615
  if(Sticky.get("swipehint"))
1559
1616
  {
1560
1617
  $(".sticky-swipehint-container").each(function() {
@@ -1563,7 +1620,7 @@ $.fn.serializeObject = function () {
1563
1620
  image.src = $(this).data("image");
1564
1621
 
1565
1622
  var span = document.createElement("span");
1566
- span.append(image);
1623
+ span.append(image);
1567
1624
 
1568
1625
  $(this).append(span);
1569
1626
  });