我正在使用jQuery创建一个todo list webapp。我有一个删除按钮,删除表中的整行。我让它工作得很好但是一旦我为移除按钮添加动画它就不再有效了。我想要发生的是用户单击删除按钮,按钮中的动画发生,然后行被删除。我究竟做错了什么?提前感谢您的帮助。
package com.soquestion
import breeze.linalg.support._
import breeze.linalg.support.CanTraverseValues._
import breeze.stats._
import scala.annotation.tailrec
import scala.collection.SortedMap
import scala.language.implicitConversions
object proof {
type Series = SortedMap[Int, Double]
def example: Double = {
// ideally this implicit would go in a scope higher up so it could be
// brought in wherever it's needed, but this works for a sample
implicit object SeriesIter extends CanTraverseValues[Series, Double] {
def isTraversableAgain(from: Series) = true
def traverse(from: Series, fn: ValuesVisitor[Double]): Unit = {
@tailrec def traverser(idx: Int, t: Array[Double]): Unit = {
if (idx == 1) fn.visit(t.head)
else {
fn.visit(t.head)
traverser(idx - 1, t.tail)
}
}
val v: Array[Double] = from.values.toArray
fn.zeros(0, 0d)
traverser(v.size, v)
}
}
val s: Series = SortedMap(1 -> 9.0, 2 -> 2.0, 3 -> 5.0, 4 -> 4.0, 5 -> 12.0, 6 -> 7.0, 7 -> 8.0, 8 -> 11.0, 9 -> 9.0, 10 -> 3.0, 11 -> 7.0, 12 -> 4.0, 13 -> 12.0, 14 -> 5.0, 15 -> 4.0, 16 -> 10.0, 17 -> 9.0, 18 -> 6.0, 19 -> 9.0, 20 -> 4.0)
stddev(s)
}
}
答案 0 :(得分:1)
首先,在将fadeIn
添加到DOM之前设置fadeIn
,因此它无法正常工作。
另一方面,jquery动画以异步方式运行,因此您运行$("table").on("click", ".btn-danger", function() {
var fire = $("<span>").addClass("glyphicon glyphicon-fire").attr("aria-hidden", "true")
$(this).replaceWith($("<button>").attr("type", "button").addClass("btn btn-danger btn-width").append(fire));
var instance = this;
fire.fadeIn(1000, function(){
$(instance).parent().parent().remove(); // Remove entire row
});
});
,但在它之后,您将删除父级。
我会这样做:
fadeIn
如果你查看我的代码,我会在附加-ti
之后运行它,并且我使用fadeIn的第二个参数,这是1000毫秒后的回调,所以父进程将被删除动画结束了。