Propiedad Style backgroundAttachment

Definición y uso

backgroundAttachment Establecer o retornar si la imagen de fondo debe desplazarse con el contenido o mantenerse fija.

Véase también:

Estilos HTML:Propiedad background

Tutorial de CSS:Fondo CSS

Manual de referencia de CSS:Propiedad background-attachment

Ejemplo

Ejemplo 1

Establecer la imagen de fondo como fija (no se desplaza):

document.body.style.backgroundAttachment = "fixed";

Prueba por tu cuenta

Ejemplo 2

Elegir scroll y local en el elemento DIV:

document.getElementById("myDIV").style.backgroundAttachment = "local";

Prueba por tu cuenta

Ejemplo 3

Cambiar entre scroll y fixed:

var x = document.body.style.backgroundAttachment;
document.body.style.backgroundAttachment = (x == "scroll")? "fixed":"scroll";

Prueba por tu cuenta

Ejemplo 4

Retornar el valor de la propiedad background-attachment:

alert(document.body.style.backgroundAttachment);

Prueba por tu cuenta

Sintaxis

Retornar la propiedad backgroundAttachment:

object.style.backgroundAttachment

Configurar la propiedad backgroundAttachment:

object.style.backgroundAttachment = "scroll|fixed|local|initial|inherit"

Valor de la propiedad

Valor Descripción
scroll La imagen de fondo se desplaza con el elemento. Predeterminado.
fixed La imagen de fondo es fija en relación con la ventana de visualización.
local La imagen de fondo se desplaza con el contenido del elemento.
initial Establece esta propiedad en su valor predeterminado. Véase initial
inherit Hereda esta propiedad del elemento padre. Véase inherit

Detalles técnicos

Valor predeterminado: scroll
Valor de retorno: Cadena de caracteres que indica cómo la imagen de fondo se adjunta al objeto dentro del documento.
Versión de CSS: CSS1

Compatibilidad del navegador

backgroundAttachment es una característica de CSS1 (1996).

Todos los navegadores lo admiten completamente:

Chrome Edge Firefox Safari Opera IE
Chrome Edge Firefox Safari Opera IE
Soporte Soporte Soporte Soporte Soporte Soporte