jquery 手风琴菜单状态
我有一个手风琴菜单,其标题图像会根据状态(打开/关闭)而变化,问题是一旦菜单的任何部分打开,打开状态图像就会保持不变,即使菜单的该部分已关闭。 我希望一旦菜单的该部分关闭,关闭状态就会恢复。
代码
$(document).ready(function() {
//slides the element with class "menu_body" when paragraph with class
//"sidemenu_head" is clicked
$("#firstpane p.sidemenu_head").click(function() {
$(this).css({backgroundImage:"url(g/down.png)"})
.next("div.sidemenu_body")
.slideToggle(300)
.siblings("div.sidemenu_body")
.slideUp("fast");
$(this).siblings()
.css({backgroundImage:"url(left.png)"});
});
I have a accordion menu with a header image that changes based on the state (open/closed) the problem is once any part of the menu is open the open state images stays, even if the section of the menu is closed. I'd like the closed state to come back once that part of the menu is closed.
Code
$(document).ready(function() {
//slides the element with class "menu_body" when paragraph with class
//"sidemenu_head" is clicked
$("#firstpane p.sidemenu_head").click(function() {
$(this).css({backgroundImage:"url(g/down.png)"})
.next("div.sidemenu_body")
.slideToggle(300)
.siblings("div.sidemenu_body")
.slideUp("fast");
$(this).siblings()
.css({backgroundImage:"url(left.png)"});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
那确实行不通。 它只是创建了另一次单击,该单击将更改胡萝卜,但现在您必须单击两次才能显示内容(一次更改胡萝卜,再次显示)。
That doesn't really work. It just creates another click that that will change the carrot, but now you have to click twice to reveal the content (once to change the carrot and again the reveal).
Jquery 切换可能适合你。 为了简单起见,我删除了显示/隐藏 div,但您可以轻松地将其添加回来:
Jquery toggle might work for you. I removed the show/hide div for simplicity but you can easily add it back:
像这样的事情应该可以做到
*修复了缺失的),这应该可以工作。
Something like this should do it
*Fixed a missing ), this should work.
我建议使用手风琴的
change
事件。 您的处理程序将传递对关闭和打开手风琴项的标题和内容元素的引用。I recommend using the
change
event of the accordion. Your handler will be passed references to both the header and the content elements of both the closing and opening accordion item.