1

我是一名网络开发人员。对于我客户的网站,我需要对悬停特定 div 产生影响,如本网站所示。当我将鼠标悬停在 div 上时,背景应该通过旋转来改变。我怎样才能做到这一点。我只能使用 css3 过渡来缓解背景变化的效果。有没有办法在不使用 jquery 的情况下做同样的事情?

看截图在此处输入图像描述

4

2 回答 2

1

jsbin

我模拟你提供没有 jquery 的动画。实现它的关键是使用父子关系并理解动画播放时的关键点。

.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>

于 2015-04-10T04:09:01.567 回答
0

    .spin{
        position: relative;
        top: 45%;
        left: 45%;
        height: 100px;
        width: 100px;
        background: red;
        box-shadow: 0 0 10px rgba(0,0,0,0.2);
        border-radius: 10px;
        border: 1px solid black;
        box-sizing: border-box;
        padding: 10px 30px;
        font-size: 25px;
        font-family: thin;
        text-align: center;
        transition: 1.5s;
    }
    .spin:hover{
        transform: rotate(360deg);
    }
    .flip{
        position: relative;
        top: 45%;
        left: 0%;
        height: 100px;
        width: 100px;
        background: red;
        box-shadow: 0 0 10px rgba(0,0,0,0.2);
        border-radius: 10px;
        border: 1px solid black;
        box-sizing: border-box;
        padding: 10px 30px;
        font-size: 25px;
        font-family: thin;
        text-align: center;
        transition: 1.5s;
    }
    .flip:hover{
        transform: rotateY(180deg);
        background: black;
    }
    @font-face {
        font-family: 'thin';
        src: url('http://fonts.gstatic.com/s/opensans/v10/cJZKeOuBrn4kERxqtaUH3VtXRa8TVwTICgirnJhmVJw.woff2');
    }
<div class='spin'>Spin me!</div>
<div class='flip'>Flip me!</div>

于 2015-04-10T04:31:55.957 回答