开发者

jQuery finding out what is at a particular X/Y co-ordinate?

开发者 https://www.devze.com 2023-01-08 17:23 出处:网络
Hey, I have the following function: function getPosition() { var cLeft = $(\'#element\').position().left;

Hey, I have the following function:

function getPosition() {
    var cLeft = $('#element').position().left;
    var cTop = $('#element').position().top;
}

I also have this:

$('ul#container>开发者_开发问答;li.node:eq('+XXX+')').css({'border' : '5px solid yellow'});

Now, is it possible to determine what index for the LI's is at the co-ordinates provided by getPosition() ?

Note: XXX denotes where I would like the index of the LI's to be.


Here is some plain JavaScript

var elementAtCoords = document.elementFromPoint(x, y);

I'm not sure support for IE, but Firefox has had it since 3.

To start going crazy with jQuery, simply wrap it

$(elementAtCoords).slideDown(2000);
0

精彩评论

暂无评论...
验证码 换一张
取 消