下面有更多 "亲自试一试" 示例。
backgroundAttachment 属性设置或返回背景图片是否应随内容滚动或固定。
返回backgroundAttachment属性:
object.style.backgroundAttachment
设置背景附件属性:
object.style.backgroundAttachment = "scroll|fixed|local|initial|inherit"
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 |
默认值: | 滚动 |
---|---|
返回值: | 一个字符串,表示背景图片如何附加到文档中的对象 |
CSS版本 | CSS1 |
backgroundAttachment
是 CSS1 (1996) 的一项功能。
所有浏览器都完全支持它:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
在滚动和固定之间切换:
let x = document.body.style.backgroundAttachment;
document.body.style.backgroundAttachment = (x == "scroll")? "fixed":"scroll";
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!