首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么不能移除background-attachment属性?

为什么不能移除background-attachment属性?
EN

Stack Overflow用户
提问于 2019-06-03 09:46:44
回答 3查看 178关注 0票数 1

因此,我尝试使用最大宽度为1024px的媒体查询来删除后台附件属性。我只是通过background-attachment: none来做这件事,除非我的devtools闪烁了一个错误,并且这个属性已经被划掉了吗?有什么想法吗?

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

代码语言:javascript
复制
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');
// }

EN

回答 3

Stack Overflow用户

发布于 2019-06-03 10:11:46

您可以使用jquery删除背景:

代码语言:javascript
复制
$("header").css("background-image", "none");

示例:

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

票数 1
EN

Stack Overflow用户

发布于 2019-06-03 11:04:53

您正在尝试修改style对象(它只反映通过style属性设置的样式,而不是通过样式表设置的样式),因此它没有被设置为删除它。您可以通过将其重新设置为default value of scroll来覆盖它。

代码语言:javascript
复制
header.style.backgroundAttachment='scroll';
票数 0
EN

Stack Overflow用户

发布于 2019-06-03 11:14:07

none不是background-attachment属性的有效值。

而且,这也不是你使用removeProperty的方式。这不是style的一种方法。

但是,您可以将其设置为空值,即您正在尝试从内联样式中删除该属性,例如:

代码语言:javascript
复制
header.style.backgroundAttachment = '';

或者,如果在样式表中设置了其他值,则可以将其设置为初始值,例如:

代码语言:javascript
复制
header.style.backgroundAttachment = 'initial';

或者只是将其设置为另一个特定值,类似于上面的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56420266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档