简体   繁体   中英

JQuery SlideDown isn't working when switched tab

I have HTML with some tabs when we hover on a tab a div slides down with details and when we hover on the second tab the first div slides up and second div slides down. everything works perfect but when i open a new tab and revisit my page the sliding isn't smooth or doesn't work.

HTML Page

<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");});
<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>

Just focus on #main-nav-item and #sub-nav-item

Copy these codes and modify with your codes.

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