开发者

document.body.style.backgroundImage vs document.body.background

What is 开发者_StackOverflow社区the difference between the two?


document.body.background refers to the deprecated background attribute of the body tag

http://www.w3schools.com/TAGS/att_body_background.asp

document.body.style.backgroundImage refers to the CSS background-image property of the body tag. It is equivalent to something like...

body { 
  background-image:url('paper.gif');
}

Use the latter :-)


There's a third important entry to consider in addition to the depracated document.body.background and the way to change the CSS background image with document.body.style.backgroundImage.... You can use document.body.style.background to change all the background properties, including color image and repeat:

document.body.style.background = "red";

or, to set more than one property

document.body.style.background="#0000FF url(example.jpg) repeat-x";

The above sets a background color, a background image, and sets a horizontal repeat for that image.

This is similar to the CSS:

body {
    background:#0000FF url('example.jpg') repeat-x; }

( here's a little more info about document.body.style.background at W3Schools... I'm sure there's more complete info elsewhere though )


document.body.background: You are not using CSS.

document.body.style.backgroundImage: you are setting using CSS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜