Latest web development tutorials

propriedade HTML DOM Estilo backgroundAttachment

Estilo Object Reference estilo Objects

Definição e Uso

backgroundAttachment conjuntos de propriedades ou retorna a imagem de fundo é fixa ou rolagem com o resto da página.

gramática

Definindo as propriedades backgroundAttachment:

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

Propriedades volta backgroundAttachment:

Object.style.backgroundAttachment

描述
scroll 背景随着元素一起滚动。这是默认。
fixed 背景保持固定。
local 背景随着元素的内容一起滚动。


Suporte a navegadores

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Todos os principais navegadores suportam backgroundAttachment propriedade.


Exemplos

Exemplos

imagem de fundo é fixa (não role):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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()">将背景图像设置为固定的</button>
<br>
<h1>Hello World!</h1>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>
<p>这是一个段落</p>

</body>
</html>

tente »


Exemplos

mais exemplos

E alternar entre a espiral fixa
Rolagem e alternar entre backgroundAttachment fixo.


Estilo Object Reference estilo Objects