我讀here,我可以用我的位置DIV的背景圖片:Javascript的DOM背景位置getelementbyid()?
var yValue = 20;
document.getElementById('a1').style.backgroundPosition = '0px ' + yValue + 'px';
但我會怎麼做這對於使用JavaScript body
background-position
,確實身體採取的getElementById()
函數參數的id = 'bodyname'
?
<!DOCTYPE html>
<html>
<head>
<style>
body
{
background-image: url('image.gif');
background-repeat: repeat;
background-attachment:fixed;
background-position: 77px 100px;
}
</style>
</head>
<body>
</body>
</html>
您應該使用$( '身體')來獲得身體 – Stiger 2013-03-08 03:50:03
是您的解決方案的JQuery?我從下面的答案中嘗試使用這個'var bodyElements = document.getElementsByTagName('body');',它不起作用。我不喜歡JQeury btw? – pandoragami 2013-03-08 07:48:21
是的,我的解決方案是Jquery。它可以幫助你跨瀏覽器:) – Stiger 2013-03-11 03:48:38