Last active
September 15, 2020 14:59
-
-
Save dustintheweb/5446076 to your computer and use it in GitHub Desktop.
Simulate a horizontal touch scroll event in skrollr.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// >> Horizontal Touch Scroll Simulator >>>>>>>>>>>>>>> | |
// prereq: skrollr.js: https://github.com/Prinzhorn/skrollr | |
function fakeHorzScroll(){ | |
var tStartX, tStopY, touch, mXPos, xPro; | |
$(window).bind('touchstart', function(e) { | |
tStartX = e.originalEvent.touches[0].pageX; | |
e.preventDefault(); | |
}); | |
$(window).bind('touchmove',function(){ | |
move = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; | |
mXPos = move.pageX; | |
xPro = mXPos-tStartX; | |
y = skrollr.init().getScrollTop(); | |
newScroll = y+xPro; | |
skrollr.init().animateTo(newScroll, {duration: 500}); | |
}); | |
} | |
if ($('html.touch').exists()) { | |
fakeHorzScroll(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi ! Trying your code, but not working...
Are you still working on it ?
Thx