Fondo de estiloAdjunto Propiedad
Ejemplo
Establezca una imagen de fondo para que sea fija (no se desplazará):
document.body.style.backgroundAttachment = "fixed";
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
La propiedad backgroundAttachment establece o devuelve si una imagen de fondo debe desplazarse con el contenido o ser fija.
Compatibilidad con navegador
Los números de la tabla especifican la primera versión del navegador que es totalmente compatible con la propiedad.
Property | |||||
---|---|---|---|---|---|
backgroundAttachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintaxis
Devuelve la propiedad backgroundAttachment:
object.style.backgroundAttachment
Establezca la propiedad backgroundAttachment:
object.style.backgroundAttachment = "scroll|fixed|local|initial|inherit"
Valores de propiedad
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 |
Detalles técnicos
Valor por defecto: | Desplazarse |
---|---|
Valor devuelto: | Una cadena, que representa cómo se adjunta la imagen de fondo al objeto dentro del documento |
Versión CSS | CSS1 |
Más ejemplos
Ejemplo
Elija entre desplazamiento y local en un elemento DIV:
document.getElementById("myDIV").style.backgroundAttachment = "local";
Ejemplo
Alternar entre scroll y fijo:
var x = document.body.style.backgroundAttachment;
document.body.style.backgroundAttachment = (x == "scroll")? "fixed":"scroll";
Ejemplo
Devuelve el valor de la propiedad background-attachment:
alert(document.body.style.backgroundAttachment);
páginas relacionadas
Tutorial CSS: Fondo CSS
Referencia de CSS: propiedad de archivo adjunto de fondo
Referencia HTML DOM: propiedad de fondo