jquery rotate image onclick

前端 未结 7 693
难免孤独
难免孤独 2020-12-17 10:30

I am trying to achieve this (90 degree rotation), but it fails without errors. This image is within a TAG where it has already a toggle jque

相关标签:
7条回答
  • 2020-12-17 11:27

    Depending on which browser versions you need to support, you could try CSS tranforms.

    First, define a CSS class like this:

    .rotated {
      transform: rotate(90deg);
      -ms-transform: rotate(90deg); /* IE 9 */
      -moz-transform: rotate(90deg); /* Firefox */
      -webkit-transform: rotate(90deg); /* Safari and Chrome */
      -o-transform: rotate(90deg); /* Opera */
    }
    

    And then you can use jQuery to add the class when clicking the link:

    <img src="down_arrow.png" onclick="$(this).addClass('rotated');" />
    
    0 讨论(0)
提交回复
热议问题