pixelLeft property
Specifies or retrieves the value of the left style property, in pixels.
With the left style property you can set or return the left position of an element with a unit designator as a string.
The pixelLeft property specifies or retrieves the left position as an integer, in pixels.
When the value of the pixelLeft property is set, the unit type of the left style property is not changed.
The value will be converted to the current unit type of the left style property.
If you want to set or retrieve the left position as a floating-point number that specifies the value in the current unit type of the left style property, use the posLeft property.
The properties mentioned above can be used to access style settings.
If you need the left position of a rendered element, you can use the offsetLeft property and the getBoundingClientRect method.
The currentStyle.pixelLeft property is read-only, all others are read/write.Syntax:
You can find the related objects in the Supported by objects section below.
Possible values:
Integer that sets or returns the left position, in pixels.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the pixelLeft property:
|
||||
<head> <script type="text/javascript"> function GetLeftPos (elem) { var leftStyle = elem.style.left; var leftPx = elem.style.pixelLeft; var leftPos = elem.style.posLeft; alert ("The left position of the button: " + leftStyle + "\n without unit type: " + leftPos + "\n in pixels: " + leftPx); } </script> </head> <body> <button style="position:absolute; left:10%; top:40%; width:160px; height:30px;" onclick="GetLeftPos (this);">Get left position!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, applet, area, b, base, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xmp
Related pages:
External links:
User Contributed Comments