php – 完全加载后显示图像

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 完全加载后显示图像脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在图像完全加载或下载到浏览器后加载图像.
不想在下载图像时显示图像.相反,我希望显示该图像的较低质量版本,直到在背景中加载高质量图像,并且当图像在背景中完全加载时,我想用该图像替换较低质量的图像.

我说有两张照片

$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()">

脚本宝典总结

以上是脚本宝典为你收集整理的php – 完全加载后显示图像全部内容,希望文章能够帮你解决php – 完全加载后显示图像所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。