来自MDN documentation to Element.offsetParent
:
<title>Place searches</title> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=key&libraries=places"> var map; var service; var infowindow; function initialize() { var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316); map = new google.maps.Map(document.getElementById('map'), { center: pyrmont, zoom: 15 }); var request = { location: pyrmont, radius: '500', type: ['restaurant'] }; service = new google.maps.places.PlacesService(map); service.nearbySearch(request, callback); } function callback(results, status) { if (status == google.maps.places.PlacesServiceStatus.OK) { for (var i = 0; i < results.length; i++) { var place = results[i]; createMarker(results[i]); } } } </script> <style> #map { height: 100%; } html, body { height: 100%; margin: 0; padding: 0; } </style> </head> <body> <div id="map"></div> <script src="https://maps.googleapis.com/maps/api/js?key=key&libraries=places&callback=initMap" async defer>
只读属性返回对包含元素的最接近(在包含层次结构中最近)的对象的引用。 如果元素未定位,则offsetParent返回最近的表,表格单元格或根元素
如果元素未定位(即HTMLElement.offsetParent
),为什么.offsetParent
会返回最近的表?为什么position: static
总是返回最近的定位元素?
我知道我的问题的答案是.offsetParent
,但为什么标准的开发人员决定了该解决方案的目的是什么?