Flip div with two sides of html

后端 未结 5 1236
星月不相逢
星月不相逢 2021-01-01 04:52

I have a login form on a site I am currently building, and I also have a signup form. I would like to add some fancy animation to it by rotating the div to the other side wh

5条回答
  •  囚心锁ツ
    2021-01-01 05:08

    You can do the animation using CSS transition and transform: rotateY() with no Javascript, other than triggering the animation by adding a class.

    Demo: http://jsfiddle.net/ThinkingStiff/9UMFg/

    CSS:

    .flip {
        backface-visibility: hidden;
        border: 1px solid black;
        height: 150px;
        position: absolute;
        transform-origin: 50% 50% 0px;
        transition: all 3s;
        width: 300px;    
    }
    
    #side-1 {
        transform: rotateY( 0deg );
    }
    
    #side-2 {
        transform: rotateY( 180deg );   
    }
    
    .flip-side-1 {    
        transform: rotateY( 0deg ) !important;
    }
    
    .flip-side-2 {
        transform: rotateY( 180deg ) !important;
    }
    

    HTML:

    login
    login sign up
    signup
    create

    Script:

    document.getElementById( 'signup' ).addEventListener( 'click', function( event ) {
    
        event.preventDefault();
        document.getElementById( 'side-2' ).className = 'flip flip-side-1';
        document.getElementById( 'side-1' ).className = 'flip flip-side-2';
    
    }, false );
    

提交回复
热议问题