代码示例:(标识:jsck_style_backgroundattachment_div)
<!DOCTYPE html>
<html>

<style> 
#myDIV {
  width: 300px;
  height: 300px;
  background: lightblue url('/static/demo/images/flower.gif') no-repeat;
  color: white;
  overflow: auto;
}
</style>

<body>

<h1>HTML Style 对象</h1>

<h2>backgroundAttachment 属性</h2>

<p>请点击单选按钮并滚动 DIV 元素以查看 background-attachment 属性的效果:</p>

<form name="myForm">
  <input type="radio" name="myAtt" value="scroll" onclick="myFunction()" checked>scroll
  <input type="radio" name="myAtt" value="local" onclick="myFunction()">local
</form>

<div id="myDIV">
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
  <h1>Hello</h1>
</div>

<script>
function myFunction() {
  if (document.forms["myForm"]["myAtt"][0].checked) {
    document.getElementById("myDIV").style.backgroundAttachment = "scroll";
  } else {
    document.getElementById("myDIV").style.backgroundAttachment = "local";
  }
}
</script>

</body>
</html>
运行结果: