|
.posAbs( [ New_Position ] ) - Absolute positioning
Gets the absolute position of an element with repect to the document parent.
Sets an element to a particular position repective to the document parent if the new position is specified. Absolute positioning DOES NOT change the "position" style to "absolute".
Parameters
Returns
Example 1
Find the absolute position and relative position of a div box. click on the box div.
JS
HTML
CSS
$.domLoaded(function() {
$.get("#box").on("click", function() {
// Get the clicked box div
var box = $.self();
// Get Absolute position
var po = box.posAbs();
alert("Absolute Position - x : " + po.x + " , y : " + po.y);
// Get Relative position
var po = box.pos();
alert("Relative Position - x : " + po.x + " , y : " + po.y);
});
});
Result
Example 2
Set relative and absolute position of box div.
JS
HTML
CSS
$.domLoaded(function() {
$.get("#btn1").on("click", function() {
// Set Absolute position
var po = $.get("#box").posAbs({x : 0, y : 0});
});
$.get("#btn2").on("click", function() {
// Set Relative position
var po = $.get("#box").pos({x : 0, y : 0});
});
});
Result
| |||||||||||||||
