Latest web development tutorials

Properti HTML DOM Style backgroundAttachment

Gaya Referensi Obyek gaya Objects

Definisi dan Penggunaan

backgroundAttachment set properti atau mengembalikan gambar latar belakang tetap atau bergulir dengan sisa halaman.

tatabahasa

Pengaturan properti backgroundAttachment:

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

Sifat Kembali backgroundAttachment:

Object.style.backgroundAttachment

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


Dukungan Browser

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Semua browser utama mendukung properti backgroundAttachment.


contoh

contoh

gambar latar belakang adalah tetap (tidak gulir):

<!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>

Coba »


contoh

contoh yang lebih

Dan beralih di antara gulungan tetap
Bergulir dan beralih antara backgroundAttachment tetap.


Gaya Referensi Obyek gaya Objects