คุณสมบัติไฟล์แนบพื้นหลัง CSS
ตัวอย่าง
ภาพพื้นหลังที่ไม่เลื่อนกับหน้า (แก้ไข):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติbackground-attachment
กำหนดว่ารูปภาพพื้นหลังจะเลื่อนไปพร้อมกับส่วนที่เหลือของหน้า หรือได้รับการแก้ไข
ค่าเริ่มต้น: | เลื่อน |
---|---|
รับการถ่ายทอด: | ไม่ |
เคลื่อนไหวได้: | ไม่. อ่านเกี่ยวกับแอนิเมชั่น |
รุ่น: | CSS1 |
ไวยากรณ์ JavaScript: | วัตถุ .style.backgroundAttachment="fixed" |
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
ไวยากรณ์ CSS
background-attachment: scroll|fixed|local|initial|inherit;
มูลค่าทรัพย์สิน
Value | Description |
---|---|
scroll | The background image will scroll with the page. This is default |
fixed | The background image will not scroll with the page |
local | The background image will scroll 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 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ภาพพื้นหลังที่จะเลื่อนพร้อมกับหน้า (เลื่อน) นี่เป็นค่าเริ่มต้น:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
ตัวอย่าง
วิธีสร้างเอฟเฟกต์การเลื่อนพารัลแลกซ์อย่างง่าย (สร้างภาพลวงตาของความลึก 3 มิติ):
.fixed-bg {
/* The background image */
background-image: url("img_tree.gif");
/* Set a specified height, or the minimum height for the background image */
min-height: 500px;
/* Set background image to fixed (don't scroll along with the page) */
background-attachment: fixed;
/* Center the background image */
background-position: center;
/* Set the background image to no repeat */
background-repeat: no-repeat;
/* Scale the background image to be as large as possible */
background-size: cover;
}
หน้าที่เกี่ยวข้อง
กวดวิชาCSS: พื้นหลัง CSS
การอ้างอิง HTML DOM: คุณสมบัติ backgroundAttachment