我们如何在 .setAttribute 中同时添加变换旋转和缩放

How we can add transform rotate and scale simultaneously in .setAttribute

我正在处理 SVG,我想添加缩放和旋转变换。旋转值是动态的,缩放值是恒定的。

我这样试过:

boxElem.setAttribute("transform", "rotate(" + rotation + "), scale(0.9)");

它不工作。只有比例值有影响。谁能告诉我如何在 JS 中的转换中添加多个属性。

setAttribute 将导致添加属性 transform,如下所示:

<div transform="rotate(rotation) scale(0.9)"></div>

您需要更新元素的 style :

boxElem.style.transform = "rotate(" + rotation + ") scale(0.9)";