CSS3 transition on click using pure CSS

前端 未结 6 1007
鱼传尺愫
鱼传尺愫 2020-11-27 04:04

I\'m trying to get an image (a plus symbol) to rotate 45 degrees to create a cross symbol. I have so far managed to achieve this using the code below but its working on hove

6条回答
  •  执笔经年
    2020-11-27 04:31

    If you want a css only solution you can use active

    .crossRotate:active {
       transform: rotate(45deg);
       -webkit-transform: rotate(45deg);
       -ms-transform: rotate(45deg);
    }
    

    But the transformation will not persist when the activity moves. For that you need javascript (jquery click and css is the cleanest IMO).

    $( ".crossRotate" ).click(function() {
        if (  $( this ).css( "transform" ) == 'none' ){
            $(this).css("transform","rotate(45deg)");
        } else {
            $(this).css("transform","" );
        }
    });
    

    Fiddle

提交回复
热议问题