new to jquery here and I’ve come up with an Ajax box to appear under a link. It works correctly for links on the left side of the page but when a link is on the right, the box aligns incorrectly with the page. I’m using absolute positioning for the box ATM which is why it aligns as it does.
Is there a way to have it align correctly to the right for links on the left-side and then to the left for links on the right-side of the page. Insights really appreciated! Thanks!
Here is a rough method of doing it:
http://jsfiddle.net/PdCHZ/12/
[edit]: I updated it to use the tooltip’s width from the CSS:
[edit number 2:] if you add this:
at the beginning of
$(document).ready(function () {then the oWidth code will automatically get the width from the CSS.You could replace “300” with something like
$("#tooltip").width()so that you wouldn’t have to update it, but you probably get the idea.The magic happens here:
If you’re not familiar, this is just a shorthand if statement equivalent to this:
Then you just add modifier to the pos.left and you have your positioning.