首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动画,跳跃位置,动画

动画,跳跃位置,动画
EN

Stack Overflow用户
提问于 2015-05-08 18:30:44
回答 1查看 120关注 0票数 0

这个动画循环能更有效地完成吗?我试图让.gameBoxContent向左滑动,然后从右边滑进来。在此动画期间,框的内容将发生更改。

基本上,div应该:

1:滑出视线

2:向右跳

3:向左滑入视野

代码语言:javascript
复制
// Slide Left
$('.gameBoxContent').animate( {"left": "-950px"}, 400);

// Sure this can be done better
$('.gameBoxContent').animate( {"top": "950px"}, 1);
$('.gameBoxContent').animate( {"left": "960px"}, 0);
$('.gameBoxContent').animate( {"top": "20px"}, 1);

// Slide Right
$('.gameBoxContent').animate( {"left": "20px"}, 400);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-08 19:13:48

尝试删除top动画;将元素.css("left", window.innerWidth + $(this).width())设置为complete回调的complete .animation({left:-950});利用从$.map()循环中返回的一个函数模式;在.animate()中将this对象设置为.gameBoxContent;将settings对象的options作为参数应用于.animate()

代码语言:javascript
复制
var settings = [
  [{
    "left": "-950px"
  }, {
    duration: 400,
    complete: function() {
      $(this).css("left", window.innerWidth + $(this).width())
    }
  }],
  [{
    "left": "20px"
  }, {
    duration: 400
  }]
];


$(".gameBoxContent").queue("_fx", $.map(settings, function(options, i) {
  return function(next) {
    return $(this).animate.apply($(this), options).promise().then(next)
  }
})).dequeue("_fx");
代码语言:javascript
复制
.gameBoxContent {
  width: 100px;
  height: 100px;
  background: green;
  position: relative;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="gameBoxContent"></div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30130590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档