jquery - 如何创建动画翻转箭头动画

标签 jquery html css animation

我想制作一个类似 https://www.plantflags.com/en/ 的滚动按钮

这个网站的按钮翻转效果。示例:如果您将鼠标悬停在按钮上,那么文本应该淡出并且箭头应该从左侧出现并创建。推出后,箭头移至右侧并淡出,文本再次淡入。

示例:如果您访问该网站并滚动该按钮,您就会明白。

if you go to that website and roll-over this button then you can understand

我研究过他们的代码,CSS我能看懂,但有一个JS问题我看不懂。

你能想出我怎样才能让它像这种翻转效果吗?

有类似的html代码

<a href="#" class="promo__button" data-module="modules/AnimatedArrowButton" data-contact-button>Tell me more</a>

有数据属性modules/AnimatedArrowButton实际调用js并创建更多span

演示无效https://jsfiddle.net/cyber007/78pshojd/

最佳答案

您可以混合使用 css 和 jQuery 来实现这种效果(因为您使用 jQuery 标记了您的问题)。

var timeout = null;
var transitionEnd = true;

jQuery('.line').on("mouseenter", function() {
  if (!transitionEnd)
    return;

  _this = jQuery(this);

  _this.addClass("hide-text");

  timeout = setTimeout(function() {
    _this.addClass("in");
  }, 300);

  transitionEnd = false;
}).on("mouseleave", function() {
  clearTimeout(timeout);

  jQuery(this).addClass("out").one("transitionend", function() {
    transitionEnd = true;
    jQuery(this).removeClass("hide-text out in");
  });


});
.line {
  background-color: red;
  border: 1px solid;
  border-radius: 5px;
  color: white;
  cursor: pointer;
  display: block;
  float: left;
  font-size: 25px;
  height: 70px;
  line-height: 70px;
  margin: 30px;
  overflow: hidden;
  position: relative;
  text-align: center;
  width: 200px;
}
.line::after {
  content: " ";
  border-top: 1px solid white;
  position: absolute;
  top: 50%;
  right: 100%;
  left: -150%;
  transition: left 0.5s, right 0.3s;
  opacity: 0;
}
.line::before {
  border-right: 1px solid white;
  border-top: 1px solid white;
  content: " ";
  height: 10px;
  position: absolute;
  right: 20%;
  top: calc(50% - 5px);
  transform: rotate(45deg) scale(0.2);
  transition: all 0.5s ease 0s;
  width: 10px;
  opacity: 0;
}
.line span,
.line.out span {
  opacity: 1;
  transition: 0.5s;
  transition-delay: 0.1s;
}
.line.hide-text span {
  opacity: 0;
}
.line.in::after {
  left: 20%;
  right: 20%;
  opacity: 1;
}
.line.in::before {
  transform: rotate(45deg) scale(1);
  opacity: 1;
}
.line.out::before {
  right: -100%;
  transition-delay: 0s;
}
.line.out::after {
  left: 100%;
  right: -150%;
  transition: left 0.3s, right 0.3s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='line'>
  <span class='text'>Button Text</span>
</div>

关于jquery - 如何创建动画翻转箭头动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41546506/

相关文章:

javascript - 有关如何为列表项的背景设置动画的建议

html - 带有图像的 Flexbox 列

php - 从另一页上的特定表格单元格中选择文本?

javascript - 单击鼠标,隐藏链接并显示

jquery - 在 jQuery 中动画前缀 CSS 规则

javascript - 如何在 Javascript HTML 中显示隐藏元素

asp.net - 在 css :hover as a background image 中请求时如何提供文件

html - 我在屏幕底部设置了背景,但当我进入全屏时,下方有一个空白区域。为什么会这样?

javascript - HTML5 Javascript FileReader - 将数据提取到父函数中

html - 在 <dt> 之前显示 <dd> 数据?