我有点jQuery noob。我期待有一个div
,点击时(或其中的一个按钮)将首先缩小约10px左右的宽度和高度,然后返回到正常大小,然后翻转。我希望它每次点击都能用这个动画来回翻转。Div收缩,然后返回大小,然后翻转jQuery
我有这个至今:
的jQuery:
$('.card').click(function(){
$('.card').toggleClass('flipped');
var div = $('.front , .back');
div.animate({ width: '-=10px', height: '-=10px' });
div.animate({ width: '+=10px', height: '+=10px' });
});
CSS:
.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);
}
HTML:
<section class="container">
<div class="card" >
<div class="front">THIS</div>
<div class="back">THAT</div>
</div>
</section>
这工作翻转卡片,但它只是减去10px而不是广告请妥善保管。如果我删除$('.card').toggleClass('flipped');
它会收缩和完美的成长,如果我删除
var div = $('.front , .back');
div.animate({ width: '-=10px', height: '-=10px' });
div.animate({ width: '+=10px', height: '+=10px' });
它翻转完美。我似乎无法让他们一起工作!
这是我拥有的JSFiddle:https://jsfiddle.net/PistonLegs/qcvss2oj/1/ 您可以在小提琴中看到高度增长和宽度缩小。不知道为什么。
谢谢,伙计们!
这是超级接近!一些问题,但。我注意到在你的代码片段中,字体边从右下角收缩,然后背面从左下角收缩。是否有一种方法可以从中心收缩?我需要它看起来整个事情变得更小。另外,我需要这一切发生得更快。非常感谢! –
@NickTaylor这些都不在你的OP中,为了避免我们在评论中来回移动,请在你的帖子中清楚地说明你的最终目标。一般建议你每个帖子有1个明确的问题/问题,如果你知道你需要额外的帮助,可以发表一篇新文章,而不是在当前文章中改变/添加你想要的内容。 –
对不起!我认为我的操作很清晰。描述这是一件很难的事情。但是,如果你认为我需要缩小来自中心和动画的速度作为一个单独的问题/问题,那么我想我确实需要一个新的职位。 –