Difference between revisions of "Jquery element position"
From John Freier
(Created page with 'This section is all about how to position elements on a page.') |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
This section is all about how to position elements on a page. | This section is all about how to position elements on a page. | ||
| + | |||
| + | |||
| + | == Get Position == | ||
| + | To get the position, jquery has a method on it with two attributes. | ||
| + | |||
| + | Left | ||
| + | $(this).position().left | ||
| + | |||
| + | Top | ||
| + | $(this).position().top | ||
| + | |||
| + | |||
| + | == Set Position == | ||
| + | To set the position of an element, you will want to make the position absolute, and then set the css values. | ||
| + | |||
| + | Position Absolute | ||
| + | position:absolute; | ||
| + | |||
| + | Left | ||
| + | $(this).css('left', 100); | ||
| + | |||
| + | Top | ||
| + | $(this).css('top', 100); | ||
Latest revision as of 16:09, 5 October 2011
This section is all about how to position elements on a page.
Get Position
To get the position, jquery has a method on it with two attributes.
Left
$(this).position().left
Top
$(this).position().top
Set Position
To set the position of an element, you will want to make the position absolute, and then set the css values.
Position Absolute
position:absolute;
Left
$(this).css('left', 100);
Top
$(this).css('top', 100);