可以't在对jQueryLite的CSS调用中设置重复属性

Can't set duplicate attributes in CSS call to jQueryLite

本文关键字:调用 设置 属性 CSS jQueryLite 在对 可以      更新时间:2024-04-02

如何在对jQueryLite的单个CSS调用中设置重复属性?在angular中,我想在SVG图像上做这样的事情:

element.css({'transform': "rotate("+rot*360+"deg)",'transform': "scale("+scl+")"});

这将设置SVG图像的旋转和比例。但是,结果是最后一个"transform"属性覆盖了以前的任何属性。也就是说,我可以设置比例或旋转,但不能同时设置。

在这个例子中,期望的css看起来像:

transform: rotate(360deg); transform: scale(1)

不能同时将CSS属性设置为两个完全不同的值。

如果你写:

transform: rotate(360deg); transform: scale(1)

那么第二个值将覆盖第一个值,并且它最终将与相同

transform: scale(1)

transform属性采用以空格分隔的值列表。你需要写:

transform: rotate(360deg) scale(1);

理论上,你在JS:中也做了同样的事情

element.css({'transform': "rotate("+rot*360+"deg) scale("+scl+")"});

这与JavaScript或jQueryLite无关——在样式表中,同一属性的多个声明也会相互覆盖。

指定多个转换的正确语法是

transform: rotate(360deg) scale(1)

为什么不通过合并这些

element.css({'transform': "rotate("+rot*360+"deg) scale("+scl+")"});