一、方法

加载完成再显示:借助Image对象的onload事件,加载完时再把src赋给img标签的src;

淡人显示:起始opacity为0,利用transform过度到1

二、代码

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
margin: 0;
padding: 0;
border: 0;
}
.backgroundShow{
position: absolute;
left: 0;
top: 0;
z-index: -1;
//overflow: hidden;
overflow: scroll;
width: 80%;
height:80%;
}
.backgroundImg{
position: absolute;
left: 0;
top: 0;
z-index: -2;
} .lay_background_img{
transition: opacity 20s ease;
opacity: 0;
}
</style>
</head>
<body>
<div class="backgroundShow">
<img id="mybgimg" class="lay_background_img backgroundImg">
</div>
</body>
<script>
+function(){
loadImage('http://z.k1982.com/show_img/201303/2013033012383895.jpg',imgLoaded);
}(); function loadImage(url, callback) {
var img = new Image();
img.src = url;
img.onload = function(){ //图片下载完毕时异步调用callback函数。
callback.call(img); // 将callback函数this指针切换为img。
};
} function imgLoaded(){
var img = document.getElementById("mybgimg");
img.setAttribute("src",this.src);
if(img.style.opacity!=undefined){
img.style.opacity=1;
}
}
</script>
</html>

三、效果

http://sandbox.runjs.cn/show/tyjnjlx5

最新文章

  1. Oracle学习笔记二 初识Oracle(二)
  2. ajax实现上传文件
  3. input输入框提示语
  4. C fopen
  5. oracle 数据库导出数据
  6. centos命令
  7. js控制tr 隐藏 显示
  8. 多态and接口
  9. [Papers]MHD, $\p_3\pi$, Lebesgue space [Jia-Zhou, JMAA, 2012]
  10. SignalR 2.0入门
  11. 【JAVA错误笔记】 - Unable add facets project AnnotationWebService CXF 2-x Web Services
  12. 日志式文件系统:SGI的xfs, Reiserfs, IBM的jfs, ext3fs
  13. hdoj 1247 Hat’s Words(字典树)
  14. Spring框架学习之高级依赖关系配置(二)
  15. Mybatis(三)返回值
  16. Centos 安装dhcp及简单配置
  17. utf8_bin跟utf8_general_ci的区别
  18. (转)Linux top命令的用法详细详解
  19. getFields和getDeclaredFields
  20. pyspark在windows中的安装

热门文章

  1. [转] 使用Spring MVC构建REST风格WEB应用
  2. 【COGS 254】【POI 2001】交通网络图
  3. js-比较两个日期的大小
  4. 如何更新firefox中的flash
  5. 控件(文本类): TextBox, PasswordBox
  6. MVC 基架不支持 Entity Framework 6 或更高版本
  7. 【奶昔队ROUND#1】
  8. 转:如何用EXCEL表运用FV函数
  9. bzoj 3223 splay模板题3
  10. IOS开发中UI编写方式——code vs. xib vs.StoryBoard