繁体   English   中英

如何使用 JQuery 将 object 旋转 90 度

[英]How do I rotate an object 90 degrees using JQuery

I am trying to manipulate my html using jquery and would like to rotate the object 90 degrees so the head of the object precedes the tail. 我可以使用关键帧将 object 从右上角移动到左下角 - 但是它以水平方式转移,而不是像我希望的那样以更垂直的方式转移。

这是我的代码:

<div class="f p-2"></div>

@keyframes particleAnimationFlorida
{
0% {
      transform: translateX(-10px) translateY(0px)
  }
  100% {
      transform: translateX(-50px) translateY(300px);
  }
}

$(".f").css({"position": "absolute", "width": "10px", "height": "1px", "top": "110px", 
"right": "400px", "background-color": "black", "animation-name": "particleAnimationFlorida", 
"animation-timing-function": "linear", "animation-iteration-count": "11" });

$(".p-2").css({"position": "absolute", "display": "block", "content": "''", "width": "50px", 
"height": "1px", "background": "linear-gradient(-10deg, rgba(0,0,0,0) 0%,rgba(0,0,255,0.8) 
100%)", "transform": "translateX(10%) rotateZ(10deg)", "animation-duration": "3s"});

这是我的小提琴:

https://jsfiddle.net/bullybear/m826gkrt/212/

您的 animation 将覆盖您的 JavaScript 设置的旋转。 将旋转变换添加到 animation 中的每个关键帧。

@keyframes particleAnimationFlorida
  {
    0% {
          transform: translateX(-10px) translateY(0px) rotateZ(-80deg);
      }
      100% {
          transform: translateX(-50px) translateY(300px) rotateZ(-80deg);
      }
  }

小提琴: https://jsfiddle.net/q2j34dsy/

在 CSS 代码中添加旋转(xdeg),x - 旋转

@keyframes particleAnimationFlorida {
  0% {
    transform: translateX(-10px) translateY(0px) rotate(90deg);
  }
  100% {
    transform: translateX(-50px) translateY(300px) rotate(90deg);
  }
}

只需将rotate(90deg)添加到您的transform

https://www.w3schools.com/cssref/css3_pr_transform.asp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM