开发者

jQuery not doing what i tell it to do and slideDown

开发者 https://www.devze.com 2023-03-04 11:51 出处:网络
I have 2 functions that im running on a unordered list, the first one is wrapping a div around all li elements that are after the 6th one, and displaying none so that i can use the slidedown and slide

I have 2 functions that im running on a unordered list, the first one is wrapping a div around all li elements that are after the 6th one, and displaying none so that i can use the slidedown and slideup function to show and hide them, the slidedown and slideup works perfect on other elements on the page, just not on the li elements.

This is the jQuery im using for both the functions

<script type="text/javascript">
    jQuery(function() {                 
        jQuery('.clients-list li:gt(5)').wrapAll('<div style="display: none;" class="clientscontainer">');
    });
</script>


<script type="text/javascript">
jQuery(function(){
    jQuery('#clientsexpand').click(function(){
        if(jQuery('.clientscontainer').is(':hidden')) {
            jQuery('.clientscontainer').slideDown('slow');
            return false;
        } else {
            jQuery('.clientscontainer').slideUp('slow');
            return false;
        }
    });
});
</script>

With this code, the hidden li's do show after clicking, but it doesnt slide, it seems to pause for a few seconds, and then just show them up, then 开发者_Python百科when i click again to hide them, a blank block shows right down the page and then goes into hiding.

If anyone has any clue how i can fix this, that would be grand.

Cheers,


jQuery('#clientsexpand').click(function(){
        if(jQuery('.clientscontainer').is(':hidden')) {
            jQuery('.clientscontainer').slideDown('slow');
            return false;
        } else {
            jQuery('.clientscontainer').slideUp('slow');
            return false;
        }
    });

change to:

$('#clientsexpand').click(function(){
    $('.clientscontainer').slideToggle('slow');
});

Slidetoggle handles the if statements etc for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消