【问题标题】:How to flip an images with a specific direction如何翻转具有特定方向的图像
【发布时间】:2020-02-07 12:55:18
【问题描述】:

我还是个编码新手,请对我好:)

无论如何, 我有 Credit Card 的 2 个输入文本。 当我单击 CVV 输入文本时,它应该水平向左翻转,与到期年份输入文本应该水平向右翻转一样。 我的问题是我不知道如何给这张卡片设置一个特定的翻转方向。

<input type="text" Placeholder="Expiration Year" onclick="flip()" />
<input type="text" placeholder="cvv" onclick="flip()" />
<section class="container">
    <div class="card">
        <div class="front">1</div>
        <div class="back">2</div>
    </div>
</section>
.container {
    width: 200px;
    height: 260px;
    position: relative;
    border: 1px solid #ccc;
    -webkit-perspective: 800px;
    -moz-perspective: 800px;
    -o-perspective: 800px;
    perspective: 800px;
}

.card {
    width: 100%;
    height: 100%;
    position: absolute;
    -webkit-transition: -webkit-transform 1s;
    -moz-transition: -moz-transform 1s;
    -o-transition: -o-transform 1s;
    transition: transform 1s;
    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    -o-transform-style: preserve-3d;
    transform-style: preserve-3d;
    -webkit-transform-origin: 50% 50%;
}

.card div {
    display: block;
    height: 100%;
    width: 100%;
    line-height: 260px;
    color: white;
    text-align: center;
    font-weight: bold;
    font-size: 140px;
    position: absolute;
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    -o-backface-visibility: hidden;
    backface-visibility: hidden;
}

.card .front {
    background: red;
}

.card .back {
    background: blue;
    -webkit-transform: rotateY(180deg);
    -moz-transform: rotateY(180deg);
    -o-transform: rotateY(180deg);
    transform: rotateY(180deg);
}

.card.flipped {
    -webkit-transform: rotateY(180deg);
    -moz-transform: rotateY(180deg);
    -o-transform: rotateY(180deg);
    transform: rotateY(180deg);
}

function flip() {
    $('.card').toggleClass('flipped');
}

【问题讨论】:

  • 运行这段代码时发生了什么?
  • 我喜欢的是,当我双击相同的输入文本时它不应该翻转回来。我只是在互联网上举了一些文章的例子,但我没有找到一些关于那个 onclick 输入文本的特定翻转方向的例子。
  • 好的。所以如果我明白了,它会翻转到很远吗?在这种情况下,我将对输入上的“聚焦”事件应用相同的逻辑;当你离开场地时,它会翻转回来。
  • 此外,您还可以将代码重构为仅在尚未翻转时才翻转。
  • 已注明。谢谢

标签: javascript css credit-card flip


【解决方案1】:

我打算用半代码写这个来解释这个想法。

//pass the id of the element you want to flip    
function flip(idToFlip){    
    if(!$('#idToFlip').hasClass('flipped')){
        $('#idToFlip').addClass('flipped');

        //this function can check the state of other elements and place them in the correct state - you will have to write this yourself if needed
        cleanUpOtherElements();
    }
}
//bind this function to a focus-out/blur event to flip it back
function flipBack(idToFlipBack){
    //see above, it's almost the same
}

编写这样的内容可以防止您可能遇到的双击错误,并确保元素不会在不应该翻转时保持翻转。

【讨论】:

  • 它仍然无法正常工作:(我差点把自己撞到墙上,但我还是没有得到它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-24
  • 1970-01-01
  • 2022-11-30
  • 2010-10-05
  • 2016-02-01
  • 1970-01-01
相关资源
最近更新 更多