To get offset values โ€‹โ€‹from jquery

How to find the offset value of the image, which is enclosed in a table. A table consists of many images. I want to get the offset - left, right, top, bottom for the whole image, being in the image. I need this in jquery

Thanks,
Praveen j

+6
jquery
source share
3 answers
var elem = $("your_element"); var offset = elem.offset(); var leftValue = offset.left; var topValue = offset.top; 

To get the right and bottom values, add the width and height values โ€‹โ€‹to the left and top.

+14
source share

Read the jQuery documentation . These functions are very clearly defined.

 $("#yourImg").bind("mousemove", function(e) { var $this = $(this); var imgLeft = e.pageX - $this.offset().left; var imgTop = e.pageY - $this.offset().top; var imgBottom = $this.offset().top + $this.height() - e.pageY; var imgRight = $this.offset().left + $this.width() - e.pageX; // do more stuff here } 
+2
source share

I wrote a small plugin that does just that.

It gets the position of the item you want; left, right, top or bottom; relative to its parent or HTML document.

You can find it on my github: https://github.com/Ridle/jQuery-getOffsets

+2
source share

All Articles