html - 如何防止抖动div文字褪色

标签 html css

我有几个带有文本的 div,我对其应用了摇动动画。单击该按钮,它使 div 摇动。但是,我注意到这样做时文本不会保持清晰,在 div 晃动时它会稍微变淡。当 div 摇晃时,如何使文本保持清晰?这是我的代码:

$('.btn').click(function () {
  $('.card').addClass('card-hover')
  
  setTimeout( function() {
    $('.card').removeClass('card-hover')
  }, 1000);
  
});
body {
  background: #aaa;
}

.card-box{
  display: grid;
  grid-template-columns: 50% 50%;
  width: 600px;
  // border: 2px solid red;
}

.btn {
  margin: 40px 50px 0px 235px;
  height: 40px;
  width: 140px;
  border: 2px solid #000;
  border-radius: 20px;
}

.btn:hover{
  background-color: #888;
}

.card {
  margin: 50px 0px 0px 50px;
  height: 300px;
  width: 210px;
  border: 2px solid #000;
  border-radius: 20px;
  // background-color: #fff;
  background-color: #cce6ff;
  display: inline-block;
}

.card-hover {
  animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  perspective: 1000px;
}

@keyframes shake {
  10%, 90% {
    transform: translate3d(-1px, 0, 0);
  }
  
  20%, 80% {
    transform: translate3d(2px, 0, 0);
  }

  30%, 50%, 70% {
    transform: translate3d(-4px, 0, 0);
  }

  40%, 60% {
    transform: translate3d(4px, 0, 0);
  }
}

  .verse-text {
    font-family: 'Roboto', sans-serif;
    padding: 8px;
    margin-top: 10px;
    text-align: left;
    font-weight: 600;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="card-box">

<div class="card">
<div class="verse-text">
   The Riemann hypothesis has thus far resisted all attempts to prove it. Stieltjes (1885) published a note claiming to have proved the Mertens conjecture with c=1, a result stronger than the Riemann hypothesis and from which it would have followed. 
  </div>
</div>

<div class="card">
<div class="verse-text">
   The Riemann hypothesis was computationally tested and found to be true for the first 200000001 zeros by Brent et al. (1982), covering zeros sigma+it in the region 0 < t <81702130.19). 
  </div>
</div>
  
  
</div>


<input type="button" class="btn" value="Shake">

最佳答案

$('.btn').click(function () {
  $('.card').addClass('card-hover')
  
  setTimeout( function() {
    $('.card').removeClass('card-hover')
  }, 1000);
  
});
body {
  background: #aaa;
}

.card-box{
  display: grid;
  grid-template-columns: 50% 50%;
  width: 600px;
  // border: 2px solid red;
}

.btn {
  margin: 40px 50px 0px 235px;
  height: 40px;
  width: 140px;
  border: 2px solid #000;
  border-radius: 20px;
}

.btn:hover{
  background-color: #888;
}

.card {
  margin: 50px 0px 0px 50px;
  height: 300px;
  width: 210px;
  border: 2px solid #000;
  border-radius: 20px;
  // background-color: #fff;
  background-color: #cce6ff;
  display: inline-block;
}

.card-hover {
    animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    perspective: 1000px;
}

.card-hover .verse-text {
    animation: shakeText 0.82s cubic-bezier(.36,.07,.19,.97) both;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    perspective: 1000px;
}

@keyframes shake {
  10%, 90% {
    transform: translate3d(-1px, 0, 0);
  }
  
  20%, 80% {
    transform: translate3d(2px, 0, 0);
  }

  30%, 50%, 70% {
    transform: translate3d(-4px, 0, 0);
  }

  40%, 60% {
    transform: translate3d(4px, 0, 0);
  }
}

@keyframes shakeText {
    10%, 90% {
        transform: translate3d(1px, 0, 0);
    }
    20%, 80% {
        transform: translate3d(-2px, 0, 0);
    }
    30%, 50%, 70% {
        transform: translate3d(4px, 0, 0);
    }
    40%, 60% {
        transform: translate3d(-4px, 0, 0);
    }
    }

  .verse-text {
    font-family: 'Roboto', sans-serif;
    padding: 8px;
    margin-top: 10px;
    text-align: left;
    font-weight: 600;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="card-box">

<div class="card">
<div class="verse-text">
   The Riemann hypothesis has thus far resisted all attempts to prove it. Stieltjes (1885) published a note claiming to have proved the Mertens conjecture with c=1, a result stronger than the Riemann hypothesis and from which it would have followed. 
  </div>
</div>

<div class="card">
<div class="verse-text">
   The Riemann hypothesis was computationally tested and found to be true for the first 200000001 zeros by Brent et al. (1982), covering zeros sigma+it in the region 0 < t <81702130.19). 
  </div>
</div>
  
  
</div>


<input type="button" class="btn" value="Shake">

关于html - 如何防止抖动div文字褪色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52618241/

相关文章:

jquery - 将下拉菜单部分从悬停更改为单击

html - 移动响应磁贴

javascript - 在 Bootstrap Adminlte 模板的菜单中创建子项时不会自动折叠

html - firefox 和 chrome 渲染之间的巨大差异

javascript - 将 div 内的 div 与 Label 对齐?

javascript - 如何在 paper.js 中调整光栅(图像)的大小?

html - 并排放置元素

jquery - 排序后的自定义字体大小 : rowCallback does not work with server side processing?

php - 像 dribbble.com 这样的动态 PHP 网站

javascript - Google map v3 标记不刷新