html - CSS 动画突然移动

标签 html css

我有以下 JS fiddle :https://jsfiddle.net/ur9bpgbn/163/

.arrow {
  position: absolute;
  font-size: 16px;
  max-width: 350px;
  background: #FFF;
  height: 40px;
  line-height: 40px;
  margin-bottom: 20px;
  text-align: center;
  color: #000;
  box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
  visibility: hidden;
  opacity: 0;
  transition: visibility 0s, opacity 0.3s ease-in-out;
  z-index: 999;
}

.arrow.active {
  visibility: visible;
  opacity: 1;
}

.arrow.active.animate-left-to-right {
  animation-name: move-left-to-right;
  animation-duration: 1s;
  animation-delay: 0.6s;
  animation-iteration-count: infinite;
  animation-direction: alternative;
}

.arrow.active.animate-right-to-left {
  animation-name: move-right-to-left;
  animation-duration: 1s;
  animation-delay: 0.6s;
  animation-iteration-count: infinite;
  animation-direction: alternative;
}

@keyframes move-left-to-right {
  0% {
    transform: translateX (5%);
    box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
  }
  50% {
    transform: translateX(15%);
    box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.4);
  }
  100% {
    transform: translateX(5%);
    box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
  }
}

@keyframes move-right-to-left {
  0% {
    transform: translateX(-5%);
    box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.2);
  }
  50% {
    transform: translateX(-15%);
    box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.4);
  }
  100% {
    transform: translateX(-5%);
    box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.2);
  }
}


/*right arrow*/

.arrow-right {
  border-radius: 0px 0px 0 0px;
  background: linear-gradient(to right, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0.7));
}

.arrow-right:after {
  content: "";
  position: absolute;
  right: -20px;
  top: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  border-left: 20px solid #FFF;
  opacity: 0.7;
}

.arrow-right:before {
  content: "";
  position: absolute;
  left: -20px;
  top: 0;
  border-top: 0px solid transparent;
  border-bottom: 40px solid transparent;
  border-right: 20px solid #FFF;
  opacity: 1;
}


/*left arrow*/

.arrow-left {
  border-radius: 0 0px 0px 0;
  background: linear-gradient(to left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0.7));
}

.arrow-left:before {
  content: "";
  position: absolute;
  left: -20px;
  top: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  border-right: 20px solid #FFF;
  opacity: 0.7;
}

.arrow-left:after {
  content: "";
  position: absolute;
  right: -20px;
  top: 0;
  border-top: 0px solid transparent;
  border-bottom: 40px solid transparent;
  border-left: 20px solid #FFF;
  opacity: 1;
}
<div id="app">
  <a href="https://sporedev.ro" target="_blank">
    <div href="#" class="arrow arrow-right animate-right-to-left">This is a text</div>
  </a>
  <div href="#" class="arrow arrow-left animate-left-to-right" style="margin-top:30%; margin-left:30%;"><span class="room-desc">This is a text</span></div>
</div>

向右移动的箭头效果很好。

左边的箭头有点问题,当它到达过渡结束时突然移动。

我尝试在与左箭头相关的所有内容中应用对 CSS 的更改,但没有任何效果。该脚本有一些 JS 添加了“事件”类,我尝试删除它以简化脚本并确保它不是与 JS 相关的问题但没有效果。

尝试阅读过渡,但没有找到任何解决方案。我确信我错过了一些与 CSS 相关的东西。

如何使指向左侧的箭头平滑移动?

最佳答案

将这部分transform: translateX (5%);更新为transform: translateX (0%);

@keyframes move-left-to-right {
  0% {
    transform: translateX (0%);
    box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
  }
  50% {
    transform: translateX(15%);
    box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.4);
  }
  100% {
    transform: translateX(0%);
    box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
  }
}

https://jsfiddle.net/ur9bpgbn/168/

我相信小跳跃是 0-5%,它没有动画,所以它只是跳跃

关于html - CSS 动画突然移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49237140/

相关文章:

javascript - 已安装实时服务器但无法在 VS 代码中运行

javascript - 对齐 ="center"解决方法

jquery - 单击三个div后如何删除类?

HTML CSS : Have two block elements side by side

jquery - 第 n 个子项影响 3 个输入组

javascript - ul li 第二行文本在使用 li :before 后未正确对齐

javascript - 单击按钮复制 div 元素及其 CSS

css - 在图像中结合背景混合模式和灰度

python - Scrapy 获取超出范围的文本

html - 0 x 0 像素 : html doesn't apply their proper dimensions