javascript - 将 backgroundSize 设置为 window.innerWidth 和 window.innerHeight
问题描述
我正在努力使我的背景图像的高度和宽度为窗口大小的 100%。
这适用于宽度部分:
var ht = document.querySelector("html");
ht.style.background = "url('treebg.jpg')";
ht.style.backgroundSize = window.innerWidth + "px";
当我添加高度时它不起作用:
var ht = document.querySelector("html");
ht.style.background = "url('treebg.jpg')";
ht.style.backgroundSize = window.innerWidth + "px" +
window.innerHeight + "px";
谢谢你的时间。
解决方案
在第一个“px”之后添加一个空格。
var ht = document.querySelector("html");
ht.style.background = "url('treebg.jpg')";
ht.style.backgroundSize = window.innerWidth + "px " + window.innerHeight + "px";
推荐阅读
- javascript - b-table 中的可单击列在第一次单击时未注册排序图标
- c# - 用 AppendLine 删除一个额外的空行?
- xml - XSLT 根据条件拆分 XML 文件
- reactjs - React Native 从数据库中选择默认值
- reactjs - 如何在 React 单元测试中不渲染某些组件
- phpmyadmin - Phpmyadmin Xampp 列宽适合页面,如何调整列宽?
- python - Google Sheets python api - 如何在保留工作表格式的同时将值写入工作表?
- php - 为什么我的网站联系表不起作用?
- asp.net-mvc - 如果成功,ASP.NET MVC 在重定向之前显示消息
- bash - 无法在 vimrc 中添加插件