【问题标题】:jQuery function to flip an image on clickjQuery函数在点击时翻转图像
【发布时间】:2013-04-29 08:14:47
【问题描述】:

我写了一些 CSS 来翻转图像。它工作正常,但我想将其转换为一个函数,以便我可以在 onclick 事件中调用该函数。

我到目前为止的演示可以在这里找到:http://jsfiddle.net/Spokey/ggUue/1/

这是图片的 HTML:

<div class="f1_container">
    <div class="shadow f1_card">
        <div class="front face">
            <img src="http://media-cdn.tripadvisor.com/media/photo-s/03/48/0b/14/dolphin-view-chalets.jpg" style="height: 281px; width: 450px;" />
        </div>
        <div class="back face center">Some text inside here</div>
    </div>
</div>

这是 CSS:

.f1_container {
    position: relative;
    margin:10px;
    width: 450px;
    height: 281px;
    z-index : 1;
    float:left;
}
.f1_container {
    -webkit-perspective: 1000;
    perspective: 1000;
}
.f1_card {
    width: 100%;
    height: 100%;
    -webkit-transform-style: preserve-3d;
    -webkit-transition: all 1.0s linear;
    transform-style: preserve-3d;
    transition: all 1.0s linear;
}
.f1_container:hover .f1_card {
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
    box-shadow: -5px 5px 5px #aaa;
}
.face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.face.back {
    display: block;
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
    box-sizing: border-box;
    color: white;
    text-align: center;
    background-color: #aaa;
}
body{width:2000px}

【问题讨论】:

  • 我在我的网站上使用这个 CSS 作为主页上的内容“滑块”。好东西。

标签: jquery html css


【解决方案1】:

将其添加到您当前的解决方案中非常简单:

CSS

:hover 状态替换为一个类:

.f1_container:hover .f1_card {}
/* becomes */
.f1_container.active .f1_card {}

JavaScript

添加这个在点击时切换新类的 JavaScript 部分:

$('.f1_container').click(function() {
    $(this).toggleClass('active');
});

演示

Try before buy

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 2011-10-02
    • 2010-11-19
    • 2012-05-29
    • 1970-01-01
    相关资源
    最近更新 更多