How can we get Position of an image and place an other image on that position using jquery

I want to know how can we get exact position of an image and place an other image on that position

excepted positions are top left, top center, top right left center, center, right center bottom left, bottom center, bottom right

For example I have a main image now I put another image on its bottom center.

Is this possible in jQuery?

Answers


User .offset() method to get the position of image. Explicitly use .offset().top or .offset().left to get top left coordinate. use .width() and .height() to get width and height of elements. Do some highschool maths and here you go. Voila you get the right answer.


Try experimenting with getBoundingClientRect().

var foo = bar.getBoundingClientRect();

You can set position of something dynamically using the returned variable foo.

foo.left, foo.right, etc.

Mdn for the api


Please try .position() function. The .position() method allows us to retrieve the current position of an element relative to the offset parent.

 var div = $( "div ");
 var position = div.position();
 alert("left: " + position.left + ", top: " + position.top);

Need Your Help

Trying my first sql left join - isn't working

php mysql join

HiI'm trying to join two database table and extract the rows to php variables. But it's my first join function, and I'm not getting any values returned to my form.

There is no attachment in the sent mail by iPhone

iphone email attachment mfmailcomposeviewcontroller

I'm trying to send a recorded sound file as attachment with MFMailComposeViewController.