Mobile Safari "hover" (x positon of finger matches x position of image)
I'm working on a web app where I don't really have web hooks for hovers (think touch device). I can get x coords of exactly where the mouse is at all times.
I need to check to se开发者_开发问答e if the x coords of the mouse is over top of an image, and then grab that image I'm over top of.
What I'm doing
I'm using jQuery right now, and what I do is setup an array (imgCoords) of the offset.left value of each image. I then use
imgCoords.indexOf(mousePosition.x);
(mousePosition.x) is made up, but you get the idea.
I use the above code to grab the image that matches that returned index
fingerCoordToImgIndex = imgCoords.indexOf(mousePosition.x);
$('img').eq(fingerCoordToImgIndex).css({'stuff'});
This only works for the initial entry of mouse over image though (finger x only matches image x, not image x + width), and seems inefficient. I think I could thrash around a little longer to get it right, but I'd love it if one of you pro's could rescue me =p
Thanks tons! -Ken
精彩评论