触发动画的鼠标悬停问题

时间:2018-08-06 21:11:38

标签: javascript jquery html css

我最近通过点击(http://jsfiddle.net/james_doe/Lqwm98cd/)触发动画发现/分叉了这个小提琴。我以此为基准,为屏幕叠加层创建了自己的触发动画,通知用户项目已复制到剪贴板。到目前为止,这是我的进度:

http://jsfiddle.net/james_doe/Lqwm98cd/25/

$('.copy-to-clipboard').click(function(){
  $target1 = $('.copy-success');
  $target1.removeClass('copy-animation');
  setTimeout("$target1.addClass('copy-animation');",100);
  $target2 = $('.copy-success span');
  $target2.removeClass('copy-animation-text');
  setTimeout("$target2.addClass('copy-animation-text');",100)
});
body{
  width: 100%;
  height: 100%;
  position: relative;
  font-family: arial;
  font-size: 20px;
}

.copy-success{
  display: table;
  margin: 0;
  padding: 25px;
  width: 100%;
  height: 100%;
  text-align: center;
  background: #91e35fe6;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  right: 0;
  top: 0;
}

.copy-success span{
  display: table-cell;
  opacity: 0;
  vertical-align: middle;
}

.copy-animation {
    -webkit-animation: success 2s ease;
    -moz-animation: success 2s ease;
    -webkit-animation-iteration-count: 1;
    -moz-animation-iteration-count: 1;
}
.copy-animation-text {
    -webkit-animation: success-text 1.8s ease;
    -moz-animation: success-text 1.8s ease;
    -webkit-animation-iteration-count: 1;
    -moz-animation-iteration-count: 1;
    -webkit-animation-delay: 0.1s;
    -moz-animation-delay: 0.1s;
}
@-webkit-keyframes success {
      0% { opacity: 0; }
     15% { opacity: 1; }
     85% { opacity: 1; }
    100% { opacity: 0; }
}
@-moz-keyframes success {
      0% { opacity: 0; }
     15% { opacity: 1; }
     85% { opacity: 1; }
    100% { opacity: 0; }
}

@-webkit-keyframes success-text {
      0% { transform: translateY(25px); }
     15% { transform: translateY(0); }
     85% { transform: translateY(0); }
    100% { transform: translateY(-25px); }
}
@-moz-keyframes success-text {
      0% { opacity: 0; transform: translateY(25px); }
     15% { opacity: 1; transform: translateY(0); }
     85% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-25px); }
}

.button {
    background-color: #ccc;
    border-radius: 10px;
    padding: 10px;
    margin: 10px;
    cursor: pointer;
    display: inline-block;
    font-family: sans-serif;
}
.button:hover {
    background-color: #eee;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="copy-success">
  <span>Copied to Clipboard</span>
</div>

<div class="button copy-to-clipboard">
    Click me
</div>

动画已完成,并在单击按钮时触发。但是,我遇到的问题是,每当单击按钮后稍稍移动鼠标,动画就会重置(疯狂移动鼠标会使其像频闪灯一样闪烁,如果我看着,这实际上很酷来创造那种效果。

我已经尝试过处理z-index,指针事件及其构建的其他方面,但是似乎没有什么可以阻止此错误。有人可以帮助防止这种情况吗?

1 个答案:

答案 0 :(得分:0)

我无法在您的小提琴中复制您的经验。

话虽如此,您是否尝试过在动画之前禁用CSS中的指针事件?

pointer-events: none;

别忘了在之后将其重新打开:

pointer-events: all;