backgroundAttachment 属性设置背景图像是否固定或者随着页面的其余部分滚动。
Object.style.backgroundAttachment=scroll|fixed
提示:请设置一种可用的背景颜色,这样的话,假如背景图像不可用,页面也可获得良好的视觉效果。
本例设置在点击按钮后把背景图像设置为固定(不滚动):
<html>
<head>
<style type="text/css">
body
{
background-color="#FFCC80";
background-image:url(bgdesert.jpg);
}
p
{
color:white;
}
</style>
<script type="text/javascript">
function changeAttachment()
{
document.body.style.backgroundAttachment="fixed";
}
</script>
</head>
<body>
<input type="button" onclick="changeAttachment()"
value="Set background-image to be fixed" />
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>