我有 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()
来检查框的高度,因为在某些情况下它可能会关闭。
最佳答案
您可以使用 .animate({ "height":"hide"})
(反之亦然)来完成此操作。
例子:
function slideUp() {
$(".slideme").animate({ "height": "hide" });
}
function slideDown() {
$(".slideme").animate({ "height": "show" });
}
jsFiddle:http://jsfiddle.net/8VVde/14/
关于jquery - 用 animate() CSS3 替换 jQuery 幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12564735/