- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
TLDR
我希望能够在 helper 被删除后通过显示原始项目移动到它的新位置而其他项目四处移动来为我的 jQuery-UI sortable 设置动画。由于某些需要固定位置的可排序对象,这变得很复杂。
项目:
该项目涉及在选项卡式界面中动态生成的 jQuery-UI portlet。选项卡和 portlet 内容本身是通过对已建立的 Web 服务的异步 AJAX 请求生成的。每个选项卡中都有数量不定的 portlet,并使用自定义滚动条显示内容。我已经使用类和在其他地方找到的关于堆栈溢出的解决方案(稍作修改)实现了对某些 portlet 的修复。当前功能的一个非常基本的实现可以在这里看到:http://jsfiddle.net/99yVq/ .
问题
在实现 portlet 修复之前,我在通过显示和隐藏占位符元素进行排序时制作动画:
$( ".content" ).sortable({
start: function(e, ui){
$(ui.placeholder).hide(300);
},
change: function (e,ui){
$(ui.placeholder).hide().show(300);
}
});
可在此处查看实际操作:http://jsfiddle.net/BWNE2/ .这工作得很好,但我觉得动画不稳定,显然需要一些戳才能让它与上面的 portlet 修复解决方案一起工作(因为它依赖于帮助程序创建来确定固定位置)。这不是我正在寻找的解决方案。
更新
是否尝试将两者结合起来(需要注意的是没有一个是真正需要的)并且可以在此处获得组合功能:http://jsfiddle.net/BWNE2/1/ .动画有效,但如您所见,.fixed portlet 与其他 portlet 一起动画,然后恢复到其原始位置。
更新结束
问题
我的理想情况是用户将 portlet 助手(我认为它是拖动过程中使用的原始项目的克隆)从其原始位置拖动到新位置。在删除 portlet 时,它们会从旧位置到新位置进行动画处理。排序期间的当前移动应该保持以给最终用户反馈,但最终的动画应该在助手放下之后发生。
有没有人对如何实现这一目标有任何想法或示例?
如果我的问题格式不合适或者您需要更多信息,请告诉我。
提前致谢。
编辑
你可以在这里看到:http://jsfiddle.net/BWNE2/2/当将 portlet 固定在位置 3(顶部右上角)时,动画效果更加不足。它在排序时通常不在正确的位置,尽管它确实在排序结束时恢复到正确的位置。
最佳答案
按照找到的解决方案in other question ,这基本上是在拖动时克隆 itens 并将它们设置为新位置的动画,我将其合并到您的代码中。
这段代码没有的是释放后的动画,我通过保存 mouseup
事件上的位置,并将拖动的元素动画化到最终位置。
最后的 fiddle :http://jsfiddle.net/hTgad/
代码:
var lastPosition;
$( "#content" ).sortable({
delay: 100,
distance: 10,
handle: '.portlet-header',
items: '.portlet:not(.fixed)',
start: function(e, ui)
{
//store the fixed itens position
$('.fixed', this).each(function(){
var $this = $(this);
$this.data('pos', $this.index());
});
// Identify the item being dragged
ui.helper.addClass("being-dragged");
var clonedItems = $("#cloned_items");
// Create a clone for every item, except the fixed ones and the one being dragged
$("#content .portlet:not(.being-dragged, .ui-sortable-placeholder, .fixed)").each(function(){
// clone the original items to make their
// absolute-positioned counterparts...
var original = $(this);
var clone = original.clone();
// 'store' the clone for later use...
original.data("clone", clone);
original.css("visibility", "hidden"); // Hide the original
// set the initial position of the clone
var position = original.position();
clone.css("left", position.left)
.css("top", position.top);
// append the clone...
clonedItems.append(clone);
});
},
change: function(e,ui)
{
//change the position of the fixed elements to the original one
$sortable = $(this);
$statics = $('.fixed', this).detach();
$helper = $('<div class="portlet" style="background-color:#000"></div>').prependTo(this);
$statics.each(function(){
var $this = $(this);
var target = $this.data('pos');
$this.insertAfter($('.portlet', $sortable).eq(target));
});
$helper.remove();
// animate all clones to the new position
$("#content .portlet:not(.being-dragged, .ui-sortable-placeholder, .fixed)").each(function(){
var item = $(this);
var clone = item.data("clone");
// stop current clone animations...
clone.stop(true, false);
var position = item.position(); // New position
clone.animate({left: position.left, top:position.top}, 500);
});
},
stop: function(e, ui){
var el = $("#content .being-dragged");
// Save the new position
var newPosition = el.position();
// Insert a placeholder for the final animation
$('<div class="portlet ui-sortable-placeholder"></div>').insertBefore(el);
el.css("left", lastPosition.left)
.css("top", lastPosition.top)
.css("position", "absolute")
.animate({left: newPosition.left, top: newPosition.top}, 300, "swing", function() {
// After the animation remove the placeholder and reset the element position
$("#content .ui-sortable-placeholder").remove();
$(this).css("left", "").css("top", "").css("position", "");
})
.removeClass("being-dragged");
// Erase the temporary itens
$("#cloned_items").empty();
// make sure all our original items are visible again...
$("#content .portlet").css("visibility", "visible");
}
});
// Save the position of the element being dragged for the final animation
$(".portlet").on("mouseup", function() {
lastPosition = $(this).position();
});
关于javascript - jQuery-UI 可排序 : Animate from original position to new after helper drop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21478403/
我想使用 linux 终端在 .txt 文档中找到字符串 animal-0**。 ** 是从 60 到 69 的数字。我想我必须在命令中使用 grep 和正则表达式:grep -E 'animal-0
在他的C# 深入一书中,Jon Skeet 试图回答以下问题: Why can't I convert List to List? 为了解释它,他从一个代码片段开始,其中包括以下两行: Animal[
我对此有点困惑,所以希望能提供一些说明。 public void addAll(List animals) 对比 public void addAll(List animals) 最佳答案 区别在于
我遇到的情况是,我有许多CALayer以“基于回合”的方式进行动画处理。我为每个CALayer上的位置设置了动画,但是它们具有完全相同的持续时间。一旦所有这些CALayer动画完成,就会启动一个新的“
我为正在拔出的刀和空闲状态设置了动画,但是无论我做什么,它们都不会在游戏中设置动画。相反,它卡住在第一帧上。这是动画窗口运行时的样子: 动画: 在检查器中: 最佳答案 我遇到了类似的问题,它归结于动画
我的单个 HTML 文件中嵌入了 2 个页面。所以它所做的是最初它显示 PAGE1,然后如果我从右向左或从左向右滑动 PAGE2 应该显示。我的问题是如何根据我的滑动更改页面动画?比如当我从右向左滑动
我想做一个动画标题。 我创建了一个 FlatList 的动画组件, 用过 onScroll函数来更新动画值。 使用绝对位置放置一个 View (Animated.View) 作为动画 FlatList
我想制作一个打开的窗帘的动画。我有两张图像:一张用于窗帘的左侧,一张用于窗帘的右侧(以红色表示)。我想用核心动画顺利地将它们滑走。我应该寻找什么类型的动画?如何实现逼真的滑动风格? 问候, 斯特凡 a
我有一个简单的旋转动画,可以让一个对象绕其轴旋转。目前它旋转得太快了,我想减慢速度,我试过增加样本??但我对动画了解不多,所以我可能过得很好。如何放慢动画速度?它只有两个键。 最佳答案 首先,通过双击
我似乎无法在上类时获得 angularjs ng-animate,而且在野外似乎也没有任何示例。以演示 fiddle 为例: http://jsfiddle.net/yfajy/ 向 CSS 添加如下
使用以下代码段:http://jsfiddle.net/sylouuu/V7a3Y/2/ 我想在动画的#log 中显示从 0% 到 100% 的进度百分比,100% 很容易通过回调... 有可能这样做
我正在 HTML 中使用 SVG 来使用折线工具定义特定的形状。我希望通过按一下按钮并在几秒钟内将特定形状的外观动画化为不同的形状。 我一直在考虑使用动画工具来更改折线点属性,但到目前为止一直无法找到
您好,在 Firefox(相当糟糕)和 Chrome 之间获得可变性能和效果(还可以)有时这不会执行第一个动画,有时会卡住。 我的结构正确吗? $notification.animate({
我在 iOS 编程时遇到了一个问题:当我尝试为我的 tableView 制作自定义编辑按钮时,我无法将其设置为动画。下面是我如何初始化 tableview: - (void)viewWillAppea
自 beta 5 以来,我注意到在 OS X 10.10 下隐式动画有一些奇怪的行为。调用动画代理有时会导致应用程序崩溃。我设置了一个非常简单的自定义 View 。这是完整的代码: import Co
我正在开发一个可折叠组件,您可以单击它来向上/向下滚动以显示/隐藏详细信息。组件如下: // component.ts import {Component, Directive, Input} fro
我正在努力了解 web animations standard和他们的 polyfill ,正如我所见,它在 Angular 动画库中运行良好(您将动画结束值设置为“*”,这将变为 div 大小的 1
我想创建一个动画闪屏,但出现此错误: Android.Content.Res.Resources+NotFoundException: File res/drawable/splash_screen.
我正在尝试对我的应用程序应用慢动作效果,就像按 Shift 时如何减慢 Mac OS 的大多数图形效果一样。 我的应用程序使用 CoreAnimation,所以我认为它应该没什么大不了的:set sp
我想以编程方式同时不在XML文件中显示两个动画,它应该 ROTATE和TRANSLATE 我怎样才能做到这一点? 请以某种方式建议我?????? 这是ma代码:> ImageView snowImg1
我是一名优秀的程序员,十分优秀!