简体   繁体   English

jQuery中slideToggle上的展开和折叠图标问题

[英]Expand and collapse icon problems on slideToggle in jQuery

I am implementing a tree view with jQuery. 我正在用jQuery实现树形视图。

I use slideToggle() to expand-collapse sub trees and change the image showing its status(expand or collapse) in slideToggle method as a function and by using what Nick learn me at this question: 我使用slideToggle()来展开-折叠子树,并在slideToggle方法中更改显示其状态(展开或折叠)状态的图像作为函数,并使用Nick在这个问题上学到的内容:

is there a toggleSrc method in jQuery? jQuery中是否有toggleSrc方法?

but its image changing is not natural. 但是它的形象改变是不自然的。 I mean it shows collapse image when sub tree opens completely and shows expand image when sub tree closes completely. 我的意思是,当子树完全打开时,它显示折叠图像;当子树完全关闭时,它显示展开图像。 The expand changing is natural but the collapse not. 扩展的变化是自然的,但崩溃不是。 I mean the collapse image should be shown when sub tree start to collapse not after it complete it. 我的意思是应该在子树开始折叠时而不是在完成折叠后显示折叠图像。

Hope I could describe my mean clearly. 希望我能清楚地描述我的意思。

Is it possible to do what I mean? 可以按照我的意思去做吗?

Thank you in advance. 先感谢您。

why don't you share what you got so far? 你为什么不分享你到目前为止得到的东西? anyway, you are toggling the images in the callback of slideToggle? 无论如何,您是否要在slideToggle的回调中切换图像? which means after the animation..try to toggle it before the slideToggle, but this will also shows the expand image at the start of the animation. 这意味着在动画之后..尝试在slideToggle之前切换它,但是这还将在动画开始时显示展开图像。

What ur asking for is possible but requires you to write a condition 您要求的是可能的,但需要您写条件

if(obj.is(':visible')) { // the sub-tree is expanded
    $img.toggleSrc(); // show image then toggle
    obj.slideToggle(function() {
        // your code WITHOUT toggleSrc
    });
} else {
    obj.slideToggle(function() {
        // your code WITH toggleSrc
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM