Sha*_*son 14 javascript events image onload
为什么onLoad没有被触发?
function FULL_IMAGE(fimage){
document.getElementById("FULL_SRC").onLoad = function(){
offsetTop = document.getElementById("FULL_SRC").height / 2;
offsetLeft = document.getElementById("FULL_SRC").width / 2;
document.getElementById("FULL_SRC").style.marginTop="-"+offsetTop+"px";
document.getElementById("FULL_SRC").style.marginLeft="-"+offsetLeft+"px";
}
document.getElementById("FULL_SRC").src=fimage;
document.getElementById("FULL_VIEW").style.display="block";
}
Run Code Online (Sandbox Code Playgroud)
ota*_*tay 37
有时当从浏览器缓存中检索图像时,onload事件不会被触发,因此你可能会做一些小问题:
function FULL_IMAGE(fimage) {
var loaded = false;
function loadHandler() {
if (loaded) {
return;
}
loaded = true;
/* your code */
}
var img = document.getElementById('FULL_SRC');
img.addEventListener('load', loadHandler);
img.src = fimage;
img.style.display = 'block';
if (img.complete) {
loadHandler();
}
}
Run Code Online (Sandbox Code Playgroud)
在我的原始代码中,我onLoad没有使用onload...第二行代码应该读取
document.getElementById("FULL_SRC").onload = function(){
Run Code Online (Sandbox Code Playgroud)
用小写的" l" onload.
| 归档时间: |
|
| 查看次数: |
72120 次 |
| 最近记录: |