ดังที่แสดงด้านล่าง:
คัดลอกรหัสรหัสดังต่อไปนี้:
//ส่งกลับประเภทอาร์เรย์
ฟังก์ชั่น findPosition(oElement) {//oElement องค์ประกอบปัจจุบัน
ถ้า (typeof (oElement.offsetParent) != 'ไม่ได้กำหนด') {
สำหรับ (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
posX += oElement.offsetLeft;
ตำแหน่ง += oElement.offsetTop;
-
-
อาร์เรย์ var = [posX, posY];
ส่งคืนอาร์เรย์;
-
//รับพิกัด X สัมบูรณ์ของตัวควบคุมที่ทำให้เกิดเหตุการณ์บนทั้งหน้า
ฟังก์ชั่น findPositionX (oElement) {
ถ้า (typeof (oElement.offsetParent) != 'ไม่ได้กำหนด') {
สำหรับ (var posX = 0; oElement; oElement = oElement.offsetParent)
-
posX += oElement.offsetLeft;
-
-
กลับ posX;
-
//รับพิกัด Y สัมบูรณ์ของตัวควบคุมที่ทำให้เกิดเหตุการณ์บนทั้งหน้า
ฟังก์ชั่น findPositionY (oElement) {
ถ้า (typeof (oElement.offsetParent) != 'ไม่ได้กำหนด') {
สำหรับ (var posY = 0; oElement; oElement = oElement.offsetParent) {
ตำแหน่ง += oElement.offsetTop;
-
-
กลับตำแหน่ง;
-