使用Javascript更改背景大小

时间:2014-07-26 19:05:04

标签: javascript css jquery-mobile

我在jquery mobile工作,我的背景是image.Due到不同的移动屏幕尺寸,我的图像不能覆盖我的全屏。只有当这个脚本有效时才有可能。

document.getElementById("pageone").style.backgroundSize = screen.width+"px" screen.height+"px";

但这不起作用

2 个答案:

答案 0 :(得分:1)

肯定你可以用CSS。

html { 
  height: 100%;
  background: url('../images/bg_cover_web.jpg') no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

答案 1 :(得分:0)

您是否尝试过使用百分比宽度?

我没有使用过jQuery mobile,但我发现meta标签对于响应式设计很重要:https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag