【发布时间】:2017-02-12 18:20:18
【问题描述】:
我有(请不要争辩)以下html
<div class="something" style="background: green;"></div>
现在需要通过 jQuery 添加position: fixed
$(".something").css("position", "fixed");
这让我在检查器中留下以下标记
<div class="something" style="background: green; position: fixed"></div>
不,我想再次从style 属性中删除; position: fixed。
我想出的唯一解决方案是通过.data() 存储初始的position-value,然后再次反转设置。
但这给我留下了以下标记..
<div class="something" style="background: green; position: static"></div>
不幸的是,之后我无法在 style-attribute 中拥有 position-property。它会覆盖我的 css 来进行一些类更改等。
我想要什么:
我现在正在寻找一种方法来删除 jQuery 放在那里的style-attribute 的部分......类似于$(".something").css("position", unset);
请不要 !important 对我的 css 提出建议!
我更多的是寻找一种干净的方法来解决这个问题,而不是在这里解决我的具体问题
【问题讨论】:
-
找出它应该在你的班级变化中处于什么位置并将其更改为那个位置?