How to make with twitter bootstrap tabs on hover instead of clicking?

前端 未结 6 1868
盖世英雄少女心
盖世英雄少女心 2021-01-31 18:36

I finally got Bootstrap tabs to work. I was wondering if there\'s a way to change the behaviour so instead of clicking just hovering the cursor would show the hidden content?

6条回答
  •  北海茫月
    2021-01-31 19:36

    In your $(document).ready or elsewhere ...

    put something like this:

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

    You wont have to modify the core bootstrap code.

    Additionally you could do this:

    $('.nav-tabs > li ').hover(function() {
      if ($(this).hasClass('hoverblock'))
        return;
      else
        $(this).find('a').tab('show');
    });
    
    $('.nav-tabs > li').find('a').click(function() {
      $(this).parent()
        .siblings().addClass('hoverblock');
    });
    

    Which will prevent hover selection after the first time a user clicks a tab.

提交回复
热议问题