Created
May 30, 2015 03:54
-
-
Save Ore4444/f0b27dbd04208da8c3d1 to your computer and use it in GitHub Desktop.
onTouchPointJS
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
function onTouchPoint(element, callback) { | |
//TODO: use pointer events | |
window.addEventListener('click', function (evt) { | |
var x = evt.clientX; | |
var y = evt.clientY; | |
console.log("mouse pos:"+ x +","+ y); | |
console.log("element pos:"+ $(element).offset().left +","+ ($(element).offset().top - $(window).scrollTop()).toString() ); | |
if(x > $(element).offset().left && | |
y > ($(element).offset().top - $(window).scrollTop()) && | |
x < $(element).offset().left + $(element).width() && | |
y < ($(element).offset().top - $(window).scrollTop()) + $(element).height() ) { | |
callback(evt); | |
} | |
}); | |
} | |
onTouchPoint($('.selector'), function(e) { | |
console.log(e.target); | |
console.log("clicked"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment