我在页面上有 jQuery slideUp 和 down 并且动画的性能非常糟糕。所以我想用 .animate() 或 .css() 替换滑动函数来利用 CSS3 动画(通常比 jQuery 更流畅)
这是我的代码
jQuery('.close').on("click", function() {
var parent = jQuery(this).parent('.parentbox');
parent.children('.box').slideUp('500');
jQuery(this).hide();
parent.children('.open').show();
parent.animate({"opacity":"0.4"});
});
jQuery('.open').on("click", function() {
var parent = jQuery(this).parent('.parentbox');
parent.children('.box').slideDown('500');
jQuery(this).hide();
parent.children('.close').show();
parent.animate({"opacity":"1"});
});
现在,如果我替换为单击.slideUp
时.animate({"height":"0px"});
如何将其恢复到以前的高度.open
?
如果上次关闭盒子,我会使用 cookie 来关闭盒子。这使我无法使用.height()
复选框的高度,因为在某些情况下它可能已关闭。