php – 完全加载后显示图像
发布时间:2020-12-13 16:47:10 所属栏目:PHP教程 来源:网络整理
导读:我想在图像完全加载或下载到浏览器后加载图像. 我不想在下载图像时显示图像.相反,我希望显示该图像的较低质量版本,直到在背景中加载高质量图像,并且当图像在背景中完全加载时,我想用该图像替换较低质量的图像. 我说有两张照片 $LQimage = "LQabc.jpg";$HQimg
我想在图像完全加载或下载到浏览器后加载图像.
我不想在下载图像时显示图像.相反,我希望显示该图像的较低质量版本,直到在背景中加载高质量图像,并且当图像在背景中完全加载时,我想用该图像替换较低质量的图像. 我说有两张照片 $LQimage = "LQabc.jpg"; $HQimg = "HQabc.jpg"; 我怎样才能使它工作? 编辑 <html> <head> <script type="text/javascript"> function load(){ var img = new Image(); var imgUrl = 'HQabc.jpg'; img.onload = function(){ // this gets run once the image has finished downloading document.getElementById('pp').src = imgUrl; } img.src = imgUrl; // this causes the image to get downloaded in the background } </script> </head> <body onload="load()"> <img id="pp" src="LQabc.jpg" width=600/> </body> </html> 解决方法
这应该这样做:
function preLoadImage(){ var img = new Image(); var imgUrl = 'HQabc.jpg'; img.onload = function(){ // this gets run once the image has finished downloading document.getElementById('idOfImgElement').src = imgUrl; } img.src = imgUrl; // this causes the image to get downloaded in the background } 如果您在页面加载后运行此功能,它应该工作: <body onload="preLoadImage()"> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |