मान लें कि आपका DOM तत्व आईडी myElement
था चलो (मेरा लक्ष्य जाँच करने के लिए दो तत्व ओवरलैप है कि क्या है।)।
document.getElementById("myElement").offsetLeft; //Left side of box
document.getElementById("myElement").offsetTop; //Top side of box
document.getElementById("myElement").offsetLeft
+ document.getElementById("myElement").offsetWidth; //Right side of box
document.getElementById("myElement").offsetTop
+ document.getElementById("myElement").offsetHeight; //Bottom side of box
नीचे और दाएँ पक्ष के लिए, कोड मूल रूप से बाएं या शीर्ष ओर करने के लिए चौड़ाई या सीमांकन बॉक्स की ऊंचाई कहते हैं।
आप इस प्रकार, के लिए, आप एक बार document.getElementById("myElement")
को परिभाषित करने और संदर्भ इस्तेमाल कर सकते हैं चाहता था, तो: Element.getBoundingClientRect
:
var myElement = document.getElementById("myElement");
myElement.offsetLeft; //Left side of box
myElement.offsetTop; //Top side of box
myElement.offsetLeft + myElement.offsetWidth; //Right side of box
myElement.offsetTop + myElement.offsetHeight; //Bottom side of box
तो उसे एक डुप्लीकेट पद है या इन पदों अपने प्रश्न का समाधान नहीं कर रहे हैं? - http://stackoverflow.com/questions/4230029/jquery-javascript-collision-detection - http://stackoverflow.com/questions/2440377/javascript-collision-detection जब मैं इसे पढ़ता हूं, तो उन्होंने समान ध्वनि किया। उम्मीद है कि उन मदद करते हैं। – shanabus