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

前端 未结 6 1866
盖世英雄少女心
盖世英雄少女心 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:40

    It's better to bind a handler on the document object so it will work with dynamically generated tabs too:

    $(document).on('mouseenter', '[data-toggle="tab"]', function () {
      $(this).tab('show');
    });
    

    Also there is a small Bootstrap plugin which automatically activates tabs on hover: https://github.com/tonystar/bootstrap-hover-tabs.

    The complete HTML using this plugin is:

    body { padding: 2rem; }
    .tab-content { margin-top: 1.5rem; }
    
    
    
    
    
    
    
    Content 1
    Content 2
    Content 3
    Content 4

提交回复
热议问题