因此,我尝试使用最大宽度为1024px的媒体查询来删除后台附件属性。我只是通过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');
// }
发布于 2019-06-03 10:11:46
您可以使用jquery删除背景:
$("header").css("background-image", "none");示例:
发布于 2019-06-03 11:04:53
您正在尝试修改style对象(它只反映通过style属性设置的样式,而不是通过样式表设置的样式),因此它没有被设置为删除它。您可以通过将其重新设置为default value of scroll来覆盖它。
header.style.backgroundAttachment='scroll';发布于 2019-06-03 11:14:07
none不是background-attachment属性的有效值。
而且,这也不是你使用removeProperty的方式。这不是style的一种方法。
但是,您可以将其设置为空值,即您正在尝试从内联样式中删除该属性,例如:
header.style.backgroundAttachment = '';或者,如果在样式表中设置了其他值,则可以将其设置为初始值,例如:
header.style.backgroundAttachment = 'initial';或者只是将其设置为另一个特定值,类似于上面的值。
https://stackoverflow.com/questions/56420266
复制相似问题