Skip to content

Instantly share code, notes, and snippets.

@dNitza
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dNitza/b2ac8833deee1197a927 to your computer and use it in GitHub Desktop.
Save dNitza/b2ac8833deee1197a927 to your computer and use it in GitHub Desktop.
Prevent touch event when trying to scroll on touch enabled device
'use strict';
var App = App || {};
App.PhotoContainerView = Backbone.View.extend({
el: '.photos-container',
scrollY: 0,
scrollYD: 0,
events: function(){
var action = (Modernizr.touch) ? 'touchend' : 'click',
e = {};
e[ 'touchstart .lightbox'] = 'setScrollY';
e[ 'touchend .lightbox'] = 'checkForScroll';
return e;
},
setScrollY: function(e){
this.scrollY = $(window).scrollTop();
},
checkForScroll: function(){
this.scrollYD = $(window).scrollTop();
if(this.scrollY !== this.scrollYD){
return false;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment