Home  >  Q&A  >  body text

javascript - Click the button to let js control the rotation of the div. It can only be rotated once, and it will no longer rotate when clicked again?

The first time the button is clicked, p will rotate 90 degrees. Clicking it again will be useless.

曾经蜡笔没有小新曾经蜡笔没有小新2711 days ago830

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-05-19 10:32:33

    Get the current degree of rotation and add 90 to it instead of setting the world to 90

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-19 10:32:33

    1. That’s because your perspective has never changed

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:32:33

    This question is easy to say, just like the answers of the two people above, neither simple nor simple.
    If you write more standardizedly.

    //获取元素
    var op = document.getElementById("box");
    
    //每次点击获取其旋转的角度
    //这里由于需要获取transform:ratate属性是比较麻烦的。
    //我们记为操作Action,得到结果为nCurrRotate。
    
    //设置新的值
    box.style.transform='rotate('+ (nCurrRotate+90) +'deg)';
    

    Action

    Action reference here: [1]: http://blog.5ibc.net/p/25577....

    reply
    0
  • Cancelreply