From 5f49c935ee4c30faa1f62ba69f8793631bd2e260 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Wed, 6 Jun 2012 00:56:28 -0300 Subject: [PATCH] Added ability to do horizontal scroll fix. Also removed unnecessary variable startY. --- scrollfix.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scrollfix.js b/scrollfix.js index 19e6d0f..014bbf2 100644 --- a/scrollfix.js +++ b/scrollfix.js @@ -9,7 +9,7 @@ var ScrollFix = function(elem) { // Variables to track inputs - var startY, startTopScroll; + var startTopScroll, startLeftScroll; elem = elem || document.querySelector(elem); @@ -19,13 +19,19 @@ var ScrollFix = function(elem) { // Handle the start of interactions elem.addEventListener('touchstart', function(event){ - startY = event.touches[0].pageY; startTopScroll = elem.scrollTop; + startLeftScroll = elem.scrollLeft; if(startTopScroll <= 0) elem.scrollTop = 1; if(startTopScroll + elem.offsetHeight >= elem.scrollHeight) elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1; + + if(startLeftScroll <= 0) + elem.scrollLeft = 1; + + if(startLeftScroll + elem.offsetWidth >= elem.scrollWidth) + elem.scrollLeft = elem.scrollWidth - elem.offsetWidth - 1; }, false); }; \ No newline at end of file