Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
74
rated 0 times [  76] [ 2]  / answers: 1 / hits: 34968  / 12 Years ago, mon, november 19, 2012, 12:00:00

I have a question about jQuery offset() function. I use it on my site to display email a friend window after clicking on email icon.



However, the window appears sticked to the right side of browser's window, not on the position of the icon. You can see it in action on http://pec.solarismedia.net/calendarday.html




$(.emailFriend).hide();
$(.emailIcon).on(click, function(e) {
$(.emailFriend).css({
position: absolute,
left: $(this).offset().left,
top: $(this).offset().top
}).fadeIn(500);
return false;
});



There is a picture showing the difference between intention and reality.


More From » jquery

 Answers
11

It's because #container has position: relative;. Thus absolute settings of the email box are relative to the #container. You have to either remove the property or calculate the value of left with something like this:



$(this).offset().left - $('#container').offset().left

[#81923] Friday, November 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonathoncamrynv

Total Points: 339
Total Questions: 98
Total Answers: 98

Location: Saint Vincent and the Grenadines
Member since Thu, Oct 15, 2020
4 Years ago
;