创建一个人工回调函数,在Jquery中启用.addclass和.css的回调?

Tay*_*Mac 2 jquery jquery-ui jquery-selectors jquery-callback

我已经在Jquery中使用了slideUp/Down函数来为我的页面上的div设置动画,但它在iPhone上运行效果不佳,所以我决定编写一个Webkit等价来解决性能问题,但是你不能将回调应用到jQuery .css或.addclass.

我有这个功能:

$('#collapse').css('height','0');
Run Code Online (Sandbox Code Playgroud)

但我需要伪造一个回调基本上使这个工作:

$('#collapse').css('height','0', function() {
//do something after
});
Run Code Online (Sandbox Code Playgroud)

有人知道怎么做吗?

Webkit动画设置为1秒.

lon*_*day 7

只是用setTimeout; jQuery无法判断内置的浏览器动画是否已完成:

$('#collapse').css('height', 0);
setTimeout(function() {
    // code will happen after the timeout has completed
}, 1000); // 1 second
Run Code Online (Sandbox Code Playgroud)

这样做的缺点是你必须在两个地方设置动画的时间.