HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Set a background-image to be fixed (will not scroll)
The backgroundAttachment property sets or returns whether a background image should scroll with the content, or be fixed.
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
backgroundAttachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Return the backgroundAttachment property:
Set the backgroundAttachment property:
Value | Description |
---|---|
scroll | The background scrolls along with the element. This is default |
fixed | The background is fixed with regard to the viewport |
local | The background scrolls along with the element's contents |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Default Value: | scroll |
---|---|
Return Value: | A String, representing how the background image is attached to the object within the document |
CSS Version | CSS1 |
Choose between scroll and local on a DIV element:
document.getElementById("myDIV").style.backgroundAttachment = "local";
Toggle between scroll and fixed:
var x = document.body.style.backgroundAttachment;
document.body.style.backgroundAttachment = (x == "scroll")? "fixed":"scroll";
Return the value of the background-attachment property:
alert(document.body.style.backgroundAttachment);
CSS tutorial: CSS Background
CSS reference: background-attachment property
HTML DOM reference: background property