jQuery CSS动画的前进和后退按钮

时间:2016-05-09 20:01:47

标签: jquery css-animations

我很好奇什么是创建这样的场景的最佳方法。

元素:

  1. 100 x 100红色块
  2. < >向后和向前按钮
  3. 按顺序排列动画。

    1. 块旋转360°
    2. 块向右移动100px
    3. 块向下移动30px
    4. 动画最初一直播放。我的问题是关于什么是在不同的动画状态(步骤1-3)之间向前或向前退步的最佳方式。或者>点击。

1 个答案:

答案 0 :(得分:0)

您可以使用JQUERY + CSS执行此操作。 我已经为你创建了2个代码 第一个代码只有CSS,动画没有悬停/点击

.box {
  width: 100px;
  height: 100px;
  background-color: #ff0000;
      -webkit-animation: test 10s;
  -o-animation: test 10s;
  animation: test 10s;
}
@keyframes test {
  10% {transform:rotate(360deg)}
  50% {position: relative;left: 100px;}
  100% {top: 30px;}
}
<div class="box">

</div>

单击CSS + JQuery的第二个代码。

$(".left").click(function(){
$(".box").animate({
left: '100px',
});
});
$(".top").click(function(){
$(".box").animate({
top: '30px',
});
});
$(".rotate").click(function(){
$(".box").css("transform", "rotate(360deg)");
});
.box {
  width: 100px;
  height: 100px;
  background-color: #ff0000;
  position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">

</div>
<div class="top">TOP</div>
<div class="left">LEFT</div>

相关问题