微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – 要在旋转时显示元素的厚度

我沿着Y轴旋转一枚硬币,通过CSS旋转90度.有没有办法让我可以在硬币旋转之后显示出硬币的厚度,我想我可以在Y轴上旋转硬币后才能放大,但是这似乎不起作用.请建议一些方法来做同样的事情,如果可能的话. link_on_js fiddle为相同.请使用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/

解决方法

您可以使用伪元素来产生类似的效果.这是一个例子: 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,.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,.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/

原文地址:https://www.jb51.cc/jquery/176219.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐