I'm not certain about the jQuery reply but I believe that will still only give
you relative image coordinate. Following this earlier post showing a method to get the
absolute x, y coordinates of a html element on a page, and stealing the same method
from PrototypeJS, the following code should do what you need,
Caveats, I think that the 0 top check is safe to use to determine if an image is
invisible or not, but it might be problematic. Also, this will only get images inside img tags, not image links or anything set with css.
// cumulative offset function stolen from PrototypeJS
var cumulativeOffset = function(element) {
var top = 0, left = 0;
do {
top += element.offsetTop || 0;
left += element.offsetLeft || 0;
element = element.offsetParent;
} while(element);
return {
top: top,
left: left
};
};
// get all images
var results = document.getElementsByTagName("img");
var images = [];
for (result in results) {
if (results.hasOwnProperty(result)) {
images.push(results[result]);
}
}
// map our offset function across the images
var offsets = images.map(cumulativeOffset);
// pull out the highest image by checking for min offset
// offset of 0 means that the image is invisible (I think...)
var highest = images[0];
var minOffset = offsets[0];
for (i in offsets) {
if (minOffset.top === 0 ||
(offsets[i].top > 0 && offsets[i].top < minOffset.top)) {
minOffset = offsets[i];
highest = images[i];
}
}
// highest is your image element
console.log(highest);