0

以下 toggleClass 不起作用:

    $nav_item = $ ('.active_wrapper, .main_nav div.arrow_up_img, .main_nav div.arrow_down_img'),
    $arrow_down = $ ('.main_nav div.arrow_down_img'),
    $arrow_up = $ ('main_nav div.arrow_up_img');

    $('.active_wrapper').click(function(e){
        e.preventDefault();
        $('.main_nav div').not($nav_item).slideToggle('slow', function(){
            $(arrow_down).toggleClass($arrow_up);
        });

    });

HTML

        <nav class="main_nav">
            <div class="active_wrapper"><a href="#">Home</a>
                <div class="arrow_down_img"></div>
            </div>
            <div><a href="about.php">About Us</a></div> 
            <div><a href="flavours.php">Flavours</a></div>
            <div><a href="stockists.php">Stockists</a></div>
            <div><a href="thecollective.php">The collective</a></div>
            <div><a href="shop.php">Shop</a></div>
        </nav>

toggleClass 用于在 2 个箭头之间交换一个向上和一个向下(您可以想象这是一个下拉菜单),但我真的不知道为什么它不起作用..

4

2 回答 2

0

正确的代码是 $arrow_down.toggleClass('arrow_up_img');

于 2012-12-17T11:00:36.710 回答
0
   nav_item = $ ('.active_wrapper, .main_nav div.arrow_up_img, .main_nav div.arrow_down_img');
   arrow_down = $ ('.main_nav div.arrow_down_img');//missing semi colon
   arrow_up = $('main_nav div.arrow_up_img');//missing semi colon

$('.active_wrapper').click(function(e){
    e.preventDefault();
    $('.main_nav div').not(nav_item).slideToggle('slow', function(){
        arrow_down.toggleClass(arrow_up);//Invalid Object assignment
    });

});​

工作演示

于 2012-12-17T11:04:55.383 回答