»
AnglaisFrançaisVietnamien

Imprimer - getPosition - JavaScriptBank.com

Version complète: jsB@nk » Snippet » getPosition
URL: https://www.javascriptbank.com/getposition.html

getPosition © JavaScriptBank.comQuand une couche dans une autre couche, il est style.left et style.top positions peuvent être "0", mais la couche elle-même peut être de 500 pixels loin de la marge. Ces fonctions seront de retour le vrai offset.

Version complète: jsB@nk » Snippet » getPosition
URL: https://www.javascriptbank.com/getposition.html



JavaScript
<script type="text/javascript">// Created by: Ultimater :: http://ultimiacian.tripod.com/// Tested and Demo by Thái Cao Phong , http://javascriptbank.com// To find the left position, add this snippet to your code:function getPositionLeft(This){var el = This;var pL = 0;while(el){pL+=el.offsetLeft;el=el.offsetParent;}return pL}// To find the top position, add this snippet to your code:function getPositionTop(This){var el = This;var pT = 0;while(el){pT+=el.offsetTop;el=el.offsetParent;}return pT}window.onload=function(){alert('   Tested by JavaScriptBank.com     \n'  +'Left: '+getPositionLeft(document.getElementById('test'))  +'\nTop: '+getPositionTop(document.getElementById('test')));}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<div style="position: absolute; width: 444px; height: 36px; z-index: 1; left:258px; top:302px" id="test"></div><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->