Created
November 15, 2013 09:31
-
-
Save spint/7481647 to your computer and use it in GitHub Desktop.
Disabling back history navigation with swipe (chrome)
This file contains 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
// http://stackoverflow.com/questions/15829172/stop-chrome-back-forward-two-finger-swipe | |
$(document).on('mousewheel', function(e) { | |
var $target = $(e.target).closest('.scrollable-h'); | |
if ($target.scrollLeft () <= 4) { | |
$target.scrollLeft(5); | |
return false; | |
} | |
}); | |
onMousewheel: function(e, delta, deltaX, deltaY){ | |
e.preventDefault(); | |
$('leftElement').scrollLeft($('leftElement').scrollLeft() + deltaX); // leftElement = container element I want to scroll left without going back/forward | |
$('downElement').scrollTop($('downElement').scrollTop() - deltaY); // this was another element within the container element | |
} | |
//Directive used in Horizon angular app (coffeescript) | |
// this disables scrolling on everything (and thus history navigation) except for elements provided in dont-disable-scroll-on | |
app.directive "disableBackButton", [ -> | |
restrict: "A" | |
link: (scope, elm, attrs) -> | |
elm.bind 'mousewheel', (e, delta, deltaX, deltaY) -> | |
if attrs.dontDisableScrollOn | |
el = $(e.target).closest(attrs.dontDisableScrollOn) | |
if el.length > 0 | |
e.preventDefault() | |
# el = $(e.target).closest('.scroll-me') | |
$(el).scrollLeft($(el).scrollLeft() + deltaX) | |
$(el).scrollTop($(el).scrollTop() - deltaY) | |
return false | |
e.preventDefault() | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment