Hi i am struggling with the following
i have knocked up a little sample to try and show what i am trying to do.
What i want to happen is when the red line passes over the blue line get the red lines data attribute comment.
i am trying to use jquery closest to detect the closest div like below.
var count = 1;
setInterval(function(){
leftPixels = count++;
console.log(leftPixels);
$('.scruber').css('left','-' + leftPixels * 10 + 'px');
var markerData = $('.eventLine').closest('.marker').data('comment');
$('.output').html(markerData);
console.log(markerData);
},1000);
Would really appreciate some help with this
Thanks
You can do this using document.elementFromPoint(x, y); Here is an example.
Tested on Chrome:
var getElementBelowMe = function($me) {
var $below,
elOffset = $me.offset(),
x = elOffset.left + $me.width() / 2,
y = elOffset.top + $me.height() / 2;
$me.css("visibility", "hidden");
$below = document.elementFromPoint(x, y);
$me.css("visibility", "");
return $below;
}
var count = 1;
setInterval(function(){
leftPixels = count++;
var scruber = $('.scruber');
scruber.css('left','-' + leftPixels * 10 + 'px');
var eventLine = $('.eventLine');
var markerData = getElementBelowMe(eventLine);
if(markerData && $(markerData).hasClass("marker")) {
var txt = "Passing " + $(markerData).data("comment");
console.log(txt);
$(".output").append(txt + "<br />");
}
},100);
There are several things you must keep in mind though: