jQuery clean SlideToggle 同时适用于许多元素
我正在使用 SlideToggle 技术来显示和隐藏应用程序中 100 多个充满信息的 DIV。我有“显示全部”和“隐藏全部”按钮,我希望它们也有幻灯片切换动画(而不是仅仅显示和隐藏全部)。然而在 IE6 上,当应用于每个元素时,slideToggle 运行速度非常慢。
有谁知道如何加快速度?另外,我正在切换 msg_head 中的图标,但这并没有减慢速度。如果我删除 SlideToggle 并将其替换为仅显示/隐藏(在显示全部/隐藏全部),它会表现良好。不过,如果可能的话,我希望有动画。
<p class="msg_head" onclick="toggleSelection($(this));">Heading</p>
<div class="msg_body">
content
</div>
我的显示所有和隐藏所有函数...
function toggleSelection(element) {
element.next("msg_body").slideToggle(250);
element.find(":first-child").toggleClass("ui-icon-circle-arrow-s");
element.find(":first-child").toggleClass("ui-icon-circle-arrow-e");
}
function showall() {
$(".msg_head").each(function() {
$(this).next(".msg_body:hidden").slideToggle(250);
$(this).find(":first-child").attr('class','ui-icon ui-icon-circle-arrow-s');
});
}
function hideall() {
$(".msg_head").each(function() {
$(this).next(".msg_body:visible").slideToggle(250);
$(this).find(":first-child").attr('class','ui-icon ui-icon-circle-arrow-e');
});
}
根据记录,单个toggleSection() 函数执行完美。将 showall 和 hideall 函数中的 SlideToggle 替换为 show 和 hide 也效果很好。我真的只是想看看是否有一种方法可以让幻灯片切换动画不显得卡住。
I am using a slideToggle technique to show and hide 100+ DIVs full of information in my application. I have "Show All" and "Hide All" buttons and I'd like for them to have the slideToggle animation as well (instead of just showing and hiding all). However on IE6, the slideToggle runs really slow when being applied to each element.
Does anyone know how to speed this up? Also, I'm switching icons that are in the msg_head, but that isn't slowing it down. If I remove th slideToggle and replace it with just a show/hide (on the show all/hide all) it performs fine. However I'd like to have the animation if possible.
<p class="msg_head" onclick="toggleSelection($(this));">Heading</p>
<div class="msg_body">
content
</div>
And my show all and hide all functions...
function toggleSelection(element) {
element.next("msg_body").slideToggle(250);
element.find(":first-child").toggleClass("ui-icon-circle-arrow-s");
element.find(":first-child").toggleClass("ui-icon-circle-arrow-e");
}
function showall() {
$(".msg_head").each(function() {
$(this).next(".msg_body:hidden").slideToggle(250);
$(this).find(":first-child").attr('class','ui-icon ui-icon-circle-arrow-s');
});
}
function hideall() {
$(".msg_head").each(function() {
$(this).next(".msg_body:visible").slideToggle(250);
$(this).find(":first-child").attr('class','ui-icon ui-icon-circle-arrow-e');
});
}
For the record, the individual toggleSection() function performs flawlessly. And replacing the slideToggle in the showall and hideall functions with show and hide works well too. I'm really just seeing if there's a way to get the slideToggle animation without it looking choked up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不会有太大帮助,但我必须在这里简单地说“不”。同时动画 100 多个 DIV 似乎有点多,但当访问者在一台像样的机器上运行现代浏览器时,您可能能够摆脱它。但如果您希望在 IE6 中加快速度……您无能为力。浏览器很古老,包括 javascript 渲染引擎,永远无法在看起来流畅漂亮的同时完成您想要的事情。
This isn't going to be much help, but I'm going to have to go with a simple "No" here. Simultaneously animating 100+ DIV's seems a bit much, but you might be able to get away with it when a visitor is running a modern browser on a decent machine. But if you're looking to speed this up specifically in IE6... there is not much you can do. The browser is ancient, including the javascript rendering engine, and will never be able to do what you're wanting it to while looking smooth and pretty.
您使用什么版本的 jQuery?如果您没有使用最新版本(1.4.1),那么我强烈建议您升级。 jQuery 的开发人员对最新版本进行了重大性能改进,以解决您上面描述的问题。以下是发行说明的链接,了解更多信息:http://jquery14.com/day- 01/jquery-14
What version of jQuery are you using? If you're not using the latest (1.4.1) then I highly recommend upgrading. The developers of jQuery did a major performance overhaul for the latest version to address issues such as the one you describe above. Here is a link to the release notes for more information: http://jquery14.com/day-01/jquery-14