javascript - 为什么我不能删除背景附件属性?

标签 javascript html css media-queries

因此,我尝试使用最大宽度为 1024 像素的媒体查询删除背景附件属性。我只是通过 background-attachment: none 来做到这一点,除了我的 devtools 闪烁错误并且该属性被划掉了吗?有什么想法吗?

https://jsfiddle.net/dfwg2nbv/1/

const ham = document.querySelector('.ham-menu');
const nav = document.querySelector('nav');
const header = document.querySelector('header');
const promise = document.querySelector('.promise');
const services = document.querySelector('.services');
const testimony = document.querySelector('.testimony');

header.style.removeProperty('background-attachment');

//detect mobile
// if ("ontouchstart" in document.documentElement) {
//   removeProps(header);
//   removeProps(promise);
//   removeProps(services);
//   removeProps(testimony);
// }

ham.addEventListener('click', animateMenu);

function animateMenu() {
	nav.classList.toggle('hamburger-open');
}

// function removeProps(node) {
// 	node.style.removeProperty('background-attachment');
// 	node.style.removeProperty('background-size');
// }

最佳答案

您可以使用 jquery 删除背景:

$("header").css("background-image", "none");

例子:

https://codepen.io/seyyedmojtaba72/pen/gJqLGE

关于javascript - 为什么我不能删除背景附件属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56420266/

相关文章:

html - 如何通过提交按钮传递参数?

html - 两个按钮和文本具有不同的对齐方式

javascript - 为什么传递给 Controller ​​函数后值是 "Undefined"

javascript - 向下滚动 iFrame - jQuery/JS

javascript - 转换 12 小时 hh :mm AM/PM to 24-hour hh:mm

javascript - 获取用户音频时的 Google Chrome Javascript 问题 - 不允许启动 AudioContext

html - 生成一个小时:minute select list

html,将链接显示为普通文本

html - 如何在 Ionic-Angular 中动态更改图标颜色?

javascript - CSS使div占用剩余空间