切换选项卡时,JQuery SlideDown无效

时间:2014-09-16 07:19:33

标签: javascript jquery html css

当我们将鼠标悬停在标签上时,我有一些标签,div会向下滑动细节,当我们将鼠标悬停在第二个标签上时,第一个div向上滑动,第二个div向下滑动。一切都很完美但是当我打开一个新标签并重新访问我的页面时,滑动不顺畅或不起作用。

HTML页面

<div id="navbar">
    <table id="navbar_link" class="navbar_link_index">
        <tr>
            <td id="about"><a href="TEMP">TEMP </a></td>
            <td id="services"><a href="TEMP">TEMP</a></td>
            <td id="products"><a href="TEMP">TEMP</a></td>
            <td><a href="TEMP">TEMP</a></td>
            <td><a href="TEMP">TEMP</a></td>
            <td><a href="TEMP">TEMP</a></td>
        </tr>
    </table>
</div>

<div class="nav_details" id="one"><table class="nav_details_table"><tr><td width="50%"><a href="about.html"><h3>TEMP</h3><p>TEMP<br></p></a></td width="50%"><td><h3>TEMP</h3> 
    <p>TEMP</p></td></tr></table></div>

    <div class="nav_details" id="two"><table class="nav_details_table servicetbl"><tr><td width="50%"><a href="about.html"><h3>TEMP</h3><p>TEMP<br></p></a></td width="50%"><td><h3>TEMP</h3> 
        <p>TEMP</p></td></tr></table></div>

        <div class="nav_details" id="three">
            <table class="nav_details_table servicetbl"><tr><td width="50%"><a href="about.html"><h3>TEMP</h3><p>TEMP<br></p></a></td width="50%"><td><h3>TEMP</h3> 
                <p>TEMP</p></td></tr></table>
            </div>

JQUERY

$("#one").hover(function()     {$("#one").stop().slideDown().addClass("border_bottom_cls");$("#about").css("background","red");},function(){$("#one").stop().slideUp().removeClass("border_bottom_cls");$("#about").css("background","toggle");});
$("#two").hover(function(){$("#two").stop().slideDown().addClass("border_bottom_cls");$("#services").css("background","red");},function(){$("#two").stop().slideUp().removeClass("border_bottom_cls");$("#services").css("background","toggle");});
$("#three").hover(function(){$("#three").stop().slideDown().addClass("border_bottom_cls");$("#products").css("background","red");},function(){$("#three").stop().slideUp().removeClass("border_bottom_cls");$("#products").css("background","toggle");});

1 个答案:

答案 0 :(得分:0)

<script>  
  $(document).ready(function (){
    var t = null;
    $('#main-nav-item').hover(function(){
        var that = this;
        t = setTimeout(function(){
            $('#sub-nav-item').slideDown(200);
            t = null;
        }, 300);
    }, function(){
        if (t){
            clearTimeout(t);
            t = null;
        }
        else
            $('#sub-nav-item').slideUp(200);
    });
    });
</script>

只关注#main-nav-item #sub-nav-item

复制这些代码并使用您的代码进行修改。