我正在使用<script>内部执行外部脚本<head>.
现在,由于脚本在页面加载之前执行,我无法访问<body>其中的内容.在文档被"加载"(HTML完全下载并在RAM中)后,我想执行一些JavaScript.我的脚本执行时是否有任何可以挂钩的事件,这些事件会在页面加载时触发?
如果我有如下图像标记:
<img src="myimage.jpg" />
Run Code Online (Sandbox Code Playgroud)
如果我添加"async":
<img async src="myimage.jpg" />
Run Code Online (Sandbox Code Playgroud)
图像加载是否异步?
我想在页面加载后使用 queryRenderedFeatures 来填充列表,但它似乎在加载图层之前不断触发。我在下面的控制台中收到错误消息:
The layer 'Points' does not exist in the map's style and cannot be queried for features.
Run Code Online (Sandbox Code Playgroud)
要素加载后如何查询图层?我尝试遵循这些答案中的建议,但它一直返回空
这就是我现在所拥有的
map.on('load', function() {
map.addLayer({
'id': 'Points',
'type': 'circle',
'source': 'Points-45d56v',
'source-layer': 'Points-45d56v',
'layout': {
'visibility': 'visible',
},
'paint': {
'circle-radius': 6,
'circle-color': 'red'
}
});
});
$(document).ready(function(){
var features = map.queryRenderedFeatures({layers:['Points']});
console.log(features);
});
Run Code Online (Sandbox Code Playgroud) javascript ×2
asynchronous ×1
dom-events ×1
html ×1
html5 ×1
image ×1
mapbox ×1
mapbox-gl-js ×1
pageload ×1