Style backgroundAttachmentPropriété

Style 对象参考手册Objet Style

Définition et utilisation

La propriété backgroundAttachment définit ou renvoie si l'image d'arrière-plan est fixe ou défile avec le reste de la page.

Syntaxe

Définir la propriété backgroundAttachment :

Object.style.backgroundAttachment="scroll|fixed|local"

Renvoie la propriété backgroundAttachment :

Object.style.backgroundAttachment

Valeur Description
scroll L'arrière-plan défile avec l'élément. Il s'agit du comportement par défaut.
fixed L'arrière-plan reste fixe.
local L'arrière-plan défile avec le contenu de l'élément.


Prise en charge des navigateurs

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Tous les principaux navigateurs prennent en charge la propriété backgroundAttachment.


Exemple

Exemple

Définir l'image d'arrière-plan comme fixe (sans défilement) :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutoriel d'exemple (example.com)</title>
<style type="text/css">
body{
    background:#f3f3f3 url('img_tree.png') no-repeat right top;
}
</style>
<script>
function displayResult(){
    document.body.style.backgroundAttachment="fixed";
}
</script>
</head>
<body>

<button type="button" onclick="displayResult()">Définir l'image d'arrière-plan comme fixe</button>
<br>
<h1>Hello World!</h1>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>
<p>Ceci est un paragraphe</p>

</body>
</html>

Essayez-le vous-même »


实例

Plus d’exemples


Passage entre un backgroundAttachment défilant et fixe.


Style 对象参考手册Objet Style Autres extensions