Propriété de style backgroundAttachment
Exemple
Définissez une image d'arrière-plan à fixer (ne défilera pas):
document.body.style.backgroundAttachment = "fixed";
Plus d'exemples "Essayez-le vous-même" ci-dessous.
Définition et utilisation
La propriété backgroundAttachment définit ou renvoie si une image d'arrière-plan doit défiler avec le contenu ou être fixe.
Prise en charge du navigateur
Les nombres dans le tableau indiquent la première version du navigateur qui prend entièrement en charge la propriété.
Property | |||||
---|---|---|---|---|---|
backgroundAttachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Syntaxe
Renvoyez la propriété backgroundAttachment :
object.style.backgroundAttachment
Définissez la propriété backgroundAttachment :
object.style.backgroundAttachment = "scroll|fixed|local|initial|inherit"
Valeurs de propriété
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 |
Détails techniques
Valeur par défaut: | faire défiler |
---|---|
Valeur de retour : | Une chaîne, représentant la façon dont l'image d'arrière-plan est attachée à l'objet dans le document |
Version CSS | CSS1 |
Plus d'exemples
Exemple
Choisissez entre scroll et local sur un élément DIV :
document.getElementById("myDIV").style.backgroundAttachment = "local";
Exemple
Basculer entre défilement et fixe :
var x = document.body.style.backgroundAttachment;
document.body.style.backgroundAttachment = (x == "scroll")? "fixed":"scroll";
Exemple
Renvoyez la valeur de la propriété background-attachment :
alert(document.body.style.backgroundAttachment);
Pages connexes
Tutoriel CSS : Arrière-plan CSS
Référence CSS : propriété background-attachment
Référence HTML DOM : propriété background