简体   繁体   English

在顶部显示受CSS3动画影响的div

[英]Display div affected by CSS3 animation on top

I have a div card that plays an animation on click, which includes the card scaling to be larger. 我有一个div卡,它在单击时播放动画,其中包括将卡缩放到更大的比例。 The problem is that as the card scales bigger, it's edges are displayed under other cards. 问题在于,随着卡的缩放比例变大,其边缘将显示在其他卡下。 http://puu.sh/oqtEs/5c0d525f8d.png http://puu.sh/oqtEs/5c0d525f8d.png

I was able to fix this by adding z-index to the class that gets applied on click, but it did not work on Safari, but did work on Chrome, FireFox and Edge. 我可以通过将z-index添加到可在点击时应用的类中来解决此问题,但它不适用于Safari,但适用于Chrome,FireFox和Edge。

@-webkit-keyframes flipAndZoomAnim
{
   0%   { -webkit-transform: rotateY(0deg) scale(0.5) translateZ(1px) }
   20%  { -webkit-transform: rotateY(180deg) scale(0.5) translateZ(1px) }
   40%  { -webkit-transform: rotateY(180deg) scale(1.0) translateZ(1px) }
   80%  { -webkit-transform: rotateY(180deg) scale(1.0) translateZ(1px) }
   100% { -webkit-transform: rotateY(180deg) scale(0.5 ) translateZ(1px) }
}

@keyframes flipAndZoomAnim
{
   0%   { transform: rotateY(0deg) scale(0.5) translateZ(1px) }
   20%  { transform: rotateY(180deg) scale(0.5) translateZ(1px) }
   40%  { transform: rotateY(180deg) scale(1.0) translateZ(1px) }
   80%  { transform: rotateY(180deg) scale(1.0) translateZ(1px) }
   100% { transform: rotateY(180deg) scale(0.5) translateZ(1px) }
}

.flipAndZoom {
    z-index: 5;
    webkit-transform: translate3d(0,0,0);
    transform: translate3d(0,0,0);
    -webkit-animation-name: flipAndZoomAnim;
    animation-name: flipAndZoomAnim;
}

There is some solutions on how to do this online, but I found none with animations. 有一些关于如何在线执行此操作的解决方案,但是我发现动画都没有。 Including the translateZ(1px) , was suggested but did not work, as well as translate3d(0,0,0); 建议包括translateZ(1px) ,但不起作用,以及translate3d(0,0,0);

HTML 的HTML

<div id="board">
     <div id="card1" class="card">
          <figure class="front">
               <img src="front.jpg"/>
          </figure>
          <figure class="back">
               <img src="back.jpg"/>      
          </figure>
     </div>

     <div id="card2" class="card">
          <figure class="front">
              <img src="front.jpg"/>
          </figure>
          <figure class="back">
              <img src="back.jpg"/>      
          </figure>
     </div>
</div>

I have the cards displayed row by row in a div, to which they are added by JavaScript. 我在div中逐行显示卡片,并通过JavaScript将卡片添加到卡片中。

   for (int i = 0; i < 20; i++) {
        $('#board').append(card.getHTML());
    }

What I find interesting that the zoomed in card is systematically displayed under the other cards, but never over. 我发现有趣的是,放大的卡会系统地显示在其他卡的下方,但永远不会结束。

Here is the website: http://valtterilaine.bitbucket.org/public_html/ 这是网站: http : //valtterilaine.bitbucket.org/public_html/

Changing 改变中

translateZ(1px)

to

translateZ(-1px)

fixed the issue. 解决了这个问题。 Since the cards are flipped they were being translated backwards. 由于卡片被翻转,因此它们被向后翻译。

Z-index should do its job, howerver may be missing the position rule. Z索引应尽其所能,但是可能会丢失位置规则。

In order to make z-index work, you must set either on of following values for position: absolute, relative or fixed. 为了使z-index起作用,必须为位置设置以下任一值:绝对值,相对值或固定值。 In this case the 在这种情况下

position: relative;

is desired, I suppose. 我想是需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM