이 기사에서는 JavaScript에 의해 문서의 각 측면에서 요소 사이의 거리를 얻는 방법에 대해 설명합니다. 참조를 위해 공유하십시오. 특정 구현 방법은 다음과 같습니다.
다음과 같이 코드를 복사하십시오 : function getDistance (obj) {
if (! obj instance of jQuery) {
obj = $ (obj);
}
var 거리 = {};
diston.top = (obj.offset (). top - $ (document) .scrolltop ());
diston.bottom = ($ (Window) .Height () - diston.top -obj.outerheight ());
diston.left = (obj.offset (). left- $ (document) .scrollleft ());
diston.right = ($ (Window) .width () - 거리 .left- obj.outerwidth ());
반환 거리;
}
이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.