我想在图像完全加载或下载到浏览器后加载图像.
我不想在下载图像时显示图像.相反,我希望显示该图像的较低质量版本,直到在背景中加载高质量图像,并且当图像在背景中完全加载时,我想用该图像替换较低质量的图像.
我不想在下载图像时显示图像.相反,我希望显示该图像的较低质量版本,直到在背景中加载高质量图像,并且当图像在背景中完全加载时,我想用该图像替换较低质量的图像.
我说有两张照片
$LQimage = "LQabc.jpg"; $HQimg = "HQabc.jpg";
我怎样才能使它工作?
编辑
随着@codeBox发布的答案,这段代码工作..谢谢:)
<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()">
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。