Search code examples
htmlcsscss-animationsrotateanimation

Background change effect by rotation on hover via CSS3


I am a web developer. for my client's website I need to put an effect on hover a specific div as shown in this website . when i hover on a div the background should change by rotating. how can i do this. I can do only ease effect for background change using css3 transition. is there any way to do the same without using jquery ?

see the scrrenshot enter image description here


Solution

  • jsbin

    I simulate your provide the animation without jquery. The key to achieve it that use the parent & chidl relation and understand the key point when animation play.

    .hover{
      position: relative;
      width: 200px;
      height: 200px;
      background-color: #1cf;
    }
    .background{
      position: absolute;
      width: 100%;
      height: 100%;
      color: #fff;
      text-align: center;
      line-height:10;
      background-color: #c33;
      transition: all 0.3s;
      z-index: 2;
      font-size: 20px;
    }
    .content{
      position: absolute;
      width: 100%;
      height: 100%;
      background-color: #fff;
      text-align: center;
      font-size: 20px;
      opacity: 0;
      line-height: 10;
      transform: scale(-1,1);
      transition: all 0.3s;
    }
    .hover:hover .background{
      transform: scale(-1,1);
      opacity: 0;
    }
    
    .hover:hover .content{
      transform: scale(1,1);
      opacity: 1;
    }
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>JS Bin</title>
    </head>
    <body>
      <div class="hover">
       <div class="background">
       This is background!!! 
       </div> 
       <div class="content">
          This is content!
       </div>
      </div>
    </body>
    </html>