Set the background-image to be fixed - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundAttachment

Description

Set the background-image to be fixed

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body style="background:#f3f3f3 url('http://java2s.com/resources/c.png') no-repeat fixed;">

<h1>Hello World!</h1>

<p>The background-image is fixed.</p>
<p>The background-image is fixed.</p>
<p>The background-image is fixed.</p>
<p>The background-image is fixed.</p>
<p>The background-image is fixed.</p>
<p>The background-image is fixed.</p>

<button onclick="myFunction()">Get background-attachment value</button>

<script>
function myFunction() {//from  ww  w  .j a va2  s  .c  om
    console.log(document.body.style.backgroundAttachment);
}
</script>

</body>
</html>

Related Tutorials