简体   繁体   中英

javascript toggle to jQuery slow toggle slide

Hello I have a bullet tree that toggles fine, but I wanted to do a one of those sliding toggles that look pretty in jquery...can you help?

javascript:

function toggle(id) {
    var e = document.getElementById(id);
    if (e.style.display == '')
        e.style.display = 'none';
    else
        e.style.display = '';
}

html:

<ul style="text-align: left;">
    <li>
        <a href="#" onclick="toggle('node1')">All</a> <input type="checkbox" name="sors" value="A" checked="checked"/>
        <ul id="node1" style="display:none">
            <li>
                <a href="#" onclick="toggle('node2')">Organic</a>
                <ul id="node2" style="display:none">
                    <li>MCA <input type="checkbox" name="sors" value="A" checked="checked"/></li>
                    <li>MCB <input type="checkbox" name="sors" value="A" checked="checked"/></li>
                </ul>
            </li>
            <li>COMM &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="sors" value="A" checked="checked"/></li>
            <li>DMISA &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="sors" value="A" checked="checked"/></li>
        </ul>
    </li>
</ul>
function toggle(id) {
  $('#' + id).slideToggle();
}

Live Example

slideToggle doc

See jquery's show and hide functions. You can pass them a value in milliseconds to animate the showing/hiding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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