我的代码正在按照我的意愿运行,但我正在寻找关于如何修剪或修改以提高效率的任何批评:
$('.toggle-comments').hide(); // this hides the results div when the page loads.
$(".comments-toggle-click").click(function () {
$(".toggle-comments").slideToggle("slow");
$(".comments-toggle-click").remove();
});
答案 0 :(得分:2)
而不是在页面加载时调用$('.toggle-comments').hide();
,而不是使用display:none;
呈现评论?
答案 1 :(得分:1)
CSS:
.toggle-comments {
display: none;
}
JavaScript的:
$('.comments-toggle-click').click(function () {
$('.toggle-comments').slideToggle('slow', function () {
$('.comments-toggle-click').remove()
})
})
如果要在动画完成之前延迟删除链接,诀窍是传递.slideToggle
回调函数。这可能是您在问题中可能遇到的问题,也可能不是。