16

我通过 CSS 沿 Y 轴将硬币旋转 90 度。有没有办法让我可以在硬币旋转后显示硬币的厚度,我想我可以在硬币沿 Y 轴旋转后缩放 Y,但这似乎不起作用。如果可能的话,请提出一些方法来做同样的事情。link_on_js也一样。请使用 webkit 浏览器打开链接。

css

.coin {
    display: block;
    background: url("url-to-image-of-coin.jpg");
    background-size: 100% 100%;
    width: 100px;
    height: 100px;
    margin: auto;
    border-radius: 100%;
    transition: all 500ms linear;
}

.flip {
    transform: rotateY(180deg);
}

html

<div class="coin"></div>

jQuery

$('.coin').click(function() {
    $(this).toggleClass('flip');
});

小提琴

http://jsfiddle.net/7EtLu/22/

4

2 回答 2

37

您可以使用伪元素来产生类似的效果。这是一个例子:http: //jsfiddle.net/joshnh/y7rQL/

<div class="coin"></div>
body {
    transform: perspective(500px);
    transform-style: preserve-3d;
}
.coin {
    background-image: url("http://www.coolemails4u.com/wp-content/uploads/2010/10/indian_rupee.png");
    background-size: 100% 100%;
    border-radius: 100%;
    height: 100px;
    margin: 50px auto;
    position: relative;
    transition: .5s linear;
    transform-style: preserve-3d;
    width: 100px;
}
.coin:after {
    background-color: #262626;
    background-image: -webkit-linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
    bottom: 0;
    content: '';
    left: 45px;
    position: absolute;
    top: 0;
    transform: rotateY(-90deg);
    transform-origin: 100% 50%;
    width: 5px;
    z-index: -10;
}
.coin:before {
    background-color: #262626;
    background-image: -webkit-linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
    border-radius: 100%;
    content: '';
    height: 100px;
    left: 0;
    position: absolute;
    top: 0;
    transform: translateZ(-5px);
    width: 100px;
}
.coin:hover {
    transform: rotateY(90deg);
}​

此外,这是一个旋转 180 度的版本(虽然不是很好):http: //jsfiddle.net/joshnh/Bz22S/

于 2012-07-25T09:00:48.003 回答
0

@joshnh 感谢您提供的灵感,这里进行了一些修改,使其看起来更像:

  <div class="flip-card">
    <div class="flip-card-inner">
      <div class="flip-card-front"></div>
      <div class="flip-card-thick"></div>
      <div class="flip-card-back"></div>
    </div>
  </div>
.flip-card {
  background-color: transparent;
  width: 300px;
  height: 300px;
  perspective: 1000px;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  background: transparent url(https://i.imgur.com/GPCt3mC.jpg) no-repeat;
  background-size: 100% 100%;
  border-radius: 100%;
  transition: transform 4s;
  transform-style: preserve-3d;
}


.flip-card-front, .flip-card-back, .flip-card-inner:before, .flip-card-inner:after  {
  background-color: #a37131;
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 100%;
  overflow: hidden;
  z-index: 1;
}

.flip-card-inner:before {
  content: '';
  top: 0;
  left: 0;
  transform: rotateY(180deg) translateZ(1px);
  background-image: -webkit-linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
}

.flip-card-inner:after {
  content: '';
  top: 0;
  left: 0;
  transform: rotateY(180deg) translateZ(10px);
  background-image: -webkit-linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
}

.flip-card-front {
  background-color: #bbb;
  color: black;
}

.flip-card-back {
  background-color: #a37131;
  color: white;
  transform: rotateY(180deg) translateZ(11px);
}

.flip-card-thick {
  background-color: #a37131;
  background-image: -webkit-linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
  bottom: 0;
  left: 130px;
  position: absolute;
  top: 0px;
  width: 10px;
  z-index: -10;
  transform: rotateY(-90deg);
  transform-origin: 100% 50%;
}

.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
}

密码笔

于 2021-12-30T03:20:34.717 回答