How to use jquery.animate () to mock 'text-align: right'
I am creating a very simple jquery menu. On hover, I have a menu on the right, which is the left margin of my menu container. This is easy since the text is aligned within the specified container.
However, I also have a menu on the left, and because the links (left-aligned) are of different lengths, the best I can do is adjust the padding to make the text lighter with an even amount between links. Therefore, the long link text goes to the right edge of the container, buying the short text only makes it about halfway.
After reading about this, I found out that you cannot change the text align property as it is not numeric. Is there any other way to do this?
Of course I tried:
$('#selector').css('text-align':'right')
but it made the text jump to the right instead of ease.
Is there a way to ensure that all links are accessible to the outermost edge of the container?
source to share
You can make the element relative and they will animate the left / right properties
Here's the script: http://jsfiddle.net/6cAYv/
HTML:
<div id="parent">
<a href="#">Hover here</a>
</div>
JS:
$('#parent').hover(function(){
var a = $(this).find('a').first();
a.css('position', 'relative').animate({ left: $(this).width() - a.width() });
},function(){
$(this).find('a').first().animate({ left:0 });
});
source to share