]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Proper touch support for vertical sliders.
authorMarius Olbertz <marius.olbertz@gmail.com>
Tue, 22 Mar 2016 15:54:01 +0000 (16:54 +0100)
committerMarius Olbertz <marius.olbertz@gmail.com>
Tue, 22 Mar 2016 15:54:01 +0000 (16:54 +0100)
The touch util seems to emit wrong values for pageX and pageY. These values seem to miss the window.scroll amount.
I added an switch to check for this case so the scrolled amount will be considered as well.

js/foundation.slider.js

index 71c7a91b9caeb20bbcf5f6c8d0f1c4a694415e24..ee894f0a6cd42424caae20d5fc2471e6ee9a654e 100644 (file)
@@ -271,7 +271,9 @@ class Slider {
           pageXY = vertical ? e.pageY : e.pageX,
           halfOfHandle = this.$handle[0].getBoundingClientRect()[param] / 2,
           barDim = this.$element[0].getBoundingClientRect()[param],
-          barOffset = (this.$element.offset()[direction] -  pageXY),
+          // touch events emulated by the touch util give position relative to screen, add window.scroll to event coordinates...
+          windowScroll = vertical ? $(window).scrollTop() : $(window).scrollLeft(),
+          barOffset = this.$element.offset()[direction] - (this.$element.offset()[direction] < pageXY ? pageXY : (pageXY + windowScroll)),
           //if the cursor position is less than or greater than the elements bounding coordinates, set coordinates within those bounds
           barXY = barOffset > 0 ? -halfOfHandle : (barOffset - halfOfHandle) < -barDim ? barDim : Math.abs(barOffset),
           offsetPct = percent(barXY, barDim);