使用 JavaScript 更新转换属性中的 rotate() 属性
Update the rotate() property within a transform attribute using JavaScript
如何只更新 transform 属性中的 rotate(19deg)
属性而不影响translate3d()
、translate()
属性?
下面是我的divs 属性。我想使用 JavaScript 只操作 rotate() 属性,以便其他属性保持原样。
transform: translate3d(782px, 312px, 0px) translate(0px, 0px) rotate(19deg) translate(0px, 0px);
因此,在使用 JavaScript 更新后,我的divs transform 属性将如下所示:
transform: translate3d(782px, 312px, 0px) translate(0px, 0px) rotate(0deg) translate(0px, 0px);
请注意rotate(0deg)
谢谢大家
如果您的想法是将元素保留在 0 度位置,而没有通过单击返回到 19 度的选项,则可以选择:
.HTML:
<div id="rotateme">
<p class="clickme">Click Me</p>
</div>
.CSS:
#rotateme {
background-color: blue;
width: 200px;
height: 200px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
-webkit-transform: translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(19deg) translate(0px, 0px);
-ms-transform: translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(19deg) translate(0px, 0px);
transform: translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(19deg) translate(0px, 0px);
}
.clickme {
text-align: center;
padding-top: 80px;
color: #fff;
font-size: 20px;
}
j查询:
$('.clickme').click(function() {
$("#rotateme").css("-webkit-transform", "translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(0deg) translate(0px, 0px)");
$("#rotateme").css("transform", "translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(0deg) translate(0px, 0px)");
$("#rotateme").css("-ms-transform", "translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(0deg) translate(0px, 0px)");
});
我没有使用您要求的确切值,因为它会将框推到可见区域下方(至少在我当前的 Codepen 设置下),但您可以看到哪一个需要更改。此外,我正在使用过渡来实现平滑旋转和前缀,因此它可以在所有现代浏览器上运行。
此处提供了代码笔示例。
相关文章:
- RegEx删除空属性?例如,如果(class=“”||class=“”)移除;否则就下课
- 全局变量和全局对象的属性之间有什么区别吗
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 序列化数据属性中对象的最可靠方法
- 分析高度属性时出现意外值{{specs.height}}.index.html
- TypeError:无法读取属性'推'未定义的JavaScript
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- AngularJS-使用'true'属性
- 可以't使用JavaScript获取width属性
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 如何使用javascript获取嵌套对象中所有子对象的单个属性
- JavaScript Pub/Sub属性访问问题
- 从JavaScript访问struts操作中的属性
- 是否可以从父类访问子类的属性
- 如何更改reactjs中外部/独立组件的状态或属性
- 如何在选项卡上定义属性'的主窗口对象
- 使用 JavaScript 更新转换属性中的 rotate() 属性
- 我们可以使用+=来变换:rotate('x'deg);css属性通过Javascript
- 阻止' rotate '属性来自父组