/// <summary> /// Resizes an element until it's size in the given axis is zero /// </summary> /// <param name="element">the element</param> /// <param name="speedFactor">the speed factor of the animation</param> /// <param name="executeOnComplete">the code to execute when the animation finished</param> /// <returns>the animation as functioncall</returns> public static JSDirectFunctionCall DecreaseElementToZero(IJSValue element, int speedFactor = 100, params IJSPiece[] executeOnComplete) { return (new JSInstantFunction( new JSValue("function changesize(object, oldsize, newsize){var rem = newsize - oldsize;var speed = " + speedFactor + ".0;object.style.overflow = \"hidden\"; object.style.height = oldsize; function move() { var f = (rem) / speed; oldsize += f; object.style.height = oldsize + f; if (Math.abs(newsize - oldsize) < 0.1) { object.style.overflow = \"auto\"; object.style.height = newsize; clearInterval(interval0);" + ((Func <string>)(() => { string ret = ""; executeOnComplete.ToList().ForEach(piece => ret += piece.GetJsCode(SessionData.CurrentSession)); return ret; })).Invoke() + " } } var interval0 = setInterval(move, 10); } " + "var obj0 = " + element.GetJsCode(SessionData.CurrentSession, CallingContext.Default) + " var oldsize = obj0.getBoundingClientRect().height; obj0.style.overflow = \"auto\"; obj0.style.height = \"auto\"; changesize(obj0, oldsize, 0);")).DefineAndCall()); }