- (function () {
- var 图片链接 = 'http://sandbox.runjs.cn/uploads/rs/453/7voafkvp/kxtbobm4.jpg';
- var 容器 = document.createElement("div");
- document.body.appendChild(容器);
- 容器.id = "背景";
- var 图片 = document.createElement("img");
- 容器.appendChild(图片);
- 图片.id = '背景大图';
- 图片.src = 图片链接;
- //初始化图片的宽和高
- 图片.height = window.innerHeight;
- 图片.width = window.innerWidth;
- //注册到window的resize句柄,实现背景图像随窗口动态调整
- window.addEventListener("resize",
- function () {
- 图片.height = window.innerHeight;
- 图片.width = window.innerWidth;
- }, false);
- })();
- //该片段来自于http://www.codesnippet.cn/detail/121220137988.html
来源: http://www.codesnippet.cn/detail/121220137988.html