1

I write a jquery to find absolute position of each link element like the following:

$(document).ready(function(){
  $("a[href]").each(function(){
    var x = $(this).offset().left;
    var y = $(this).offset().top;
    ......
  });
});

However, if it doesn't work on links that you could only see once you hover your mouse to its container. For example, on page of http://illinois.edu, There is a link called "Future Students". If you hover your mouse there, there are more links pop up, one is "Undergraduate Admissions", but this link will give me x = 0 and y = 0 while the "Furture Students" one give me the correct position. Some other examples like http://web.cs.toronto.edu/, there are links pop up form the top green bar. Those links will give me y = some negative numbers. So how could I get absolute position of these "pop up links"? Thank you!

4

1 回答 1

1

If link's are hidden (display:none), you will not be able to get their position -

From the API

Note: jQuery does not support getting the offset coordinates of hidden elements or accounting for borders, margins, or padding set on the body element.

While it is possible to get the coordinates of elements with visibility:hidden set, display:none is excluded from the rendering tree and thus has a position that is undefined.

于 2013-06-15T20:42:07.850 回答