Set between scroll and local on a DIV element - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundAttachment

Description

Set between scroll and local on a DIV element

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/* www  .j  a v  a2s .co  m*/
    width: 300px;
    height: 300px;
    background: lightblue url('http://java2s.com/resources/a.png') no-repeat;
    color: white;
    overflow: auto;
}
</style>
</head>
<body>

<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>

Related Tutorials