简体   繁体   English

还记得并在鼠标悬停后显示先前处于活动状态的导航选项卡吗?

[英]Remember and show previously active nav-tab after hover mouseout?

I have few sub-tabs(nav-pills) under every main tab(nav-tabs). 我在每个主标签(nav-tabs)下都有几个子标签(nav-pills)。 And i want to show them on hover over main tab while going back to the active main-tab after hover. 我想将它们显示在悬停在主选项卡上的同时在悬停后返回到活动的主选项卡。

I have written jquery for hover but not sure how to go back to the previous active tab.Problem is that on mouse hover , the last hovered tab stays active. 我已经为悬停编写了jquery,但是不确定如何返回上一个活动标签。问题是在鼠标悬停时,最后一个悬停的标签保持活动状态。 My code is given below where 我的代码在下面给出

  $('.nav-tabs > li > a').hover(function () {
        //$($(this).attr('href')).show();
        $(this).tab('show');
    }, function () {
       // debugger;
        //if ($(this).hasClass('active')) {           //if ($(this).parent('li').hasClass('active')) {
        //    $($(this).attr('href')).show();
        //}
        //else {
        //    $($(this).attr('href')).hide();
        //}
    });

You will need to use a class to recall your previous state when you are done hovering. 悬停完成后,您将需要使用一个类来调用以前的状态。

$('.nav-tabs > li > a').hover(function () {
    $('.nav-tabs > li.active').addClass('lastActive');
    $(this).tab('show');
}, function () {
    $('.nav-tabs > li.lastActive').removeClass('lastActive').children('a').tab('show');
});

Also you will need to add a click event that removes your lastActive class. 另外,您还需要添加一个单击事件,以删除lastActive类。

$('.nav-tabs > li > a').click(function () {
    $('.nav-tabs > li.lastActive').removeClass('lastActive');
    $(this).tab('show');
});

Something like this :) 像这样的东西:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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