Properti style.backgroundAttachment berguna ketika BACKGROUND atau BACKGROUND-IMAGE digunakan, di mana style.backgroundAttachment mengatur bagaimana gambar ketika adanya scroll, ikut terscroll atau tidak.
Sintaks:
obj.style.backgroundAttachment = value;
Nilainya:
scroll
(default)
Gambar ikut terscroll.fixed
Gambar tidak ikut terscroll.inherit
Contoh 1:
<HTML>
<HEAD>
<TITLE>style.backgroundAttachment</TITLE>
<STYLE TYPE="text/css">
body
{
height: 900px;
background: #FFF url(picture.gif) no-repeat fixed center;
}
</STYLE>
<SCRIPT TYPE="text/javascript">
function Scroll()
{
var bodyElem = document.getElementsByTagName("body")[0];
bodyElem.style.backgroundAttachment = "scroll";
}
</SCRIPT>
</HEAD>
<BODY>
<BUTTON ONCLICK="Scroll()">Scroll!</BUTTON>
</BODY>
</HTML>
Contoh 2:
<HTML>
<HEAD>
<TITLE>style.backgroundAttachment</TITLE>
<STYLE TYPE="text/css">
body
{
height: 900px;
background: #FFF url(picture.gif) no-repeat scroll center;
}
</STYLE>
<SCRIPT TYPE="text/javascript">
function Fixed()
{
var bodyElem = document.getElementsByTagName("body")[0];
bodyElem.style.backgroundAttachment = "fixed";
}
</SCRIPT>
</HEAD>
<BODY>
<BUTTON ONCLICK="Fixed()">Fixed!</BUTTON>
</BODY>
</HTML>