Operlapping Nicescroll scrolbars in Bootstrap tabs

天涯浪子 提交于 2019-12-01 12:37:32

With Bootstrap 3 Tabs

HTML Markup

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
  <li role="presentation" class="active"><a href="#home" role="tab" data-toggle="tab">Home</a></li>
  <li role="presentation"><a href="#profile" role="tab" data-toggle="tab">Profile</a></li>
  <li role="presentation"><a href="#messages" role="tab" data-toggle="tab">Messages</a></li>
  <li role="presentation"><a href="#settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="home">...</div>
  <div role="tabpanel" class="tab-pane" id="profile">...</div>
  <div role="tabpanel" class="tab-pane" id="messages">...</div>
  <div role="tabpanel" class="tab-pane" id="settings">...</div>
</div>

JS

<script>
  $(document).ready(function() {
      $('a[data-toggle="tab"]').click(function () {
          $("tab-pane").getNiceScroll().hide();

          $($(this).attr('href')).find("tab-pane").niceScroll({
              cursorcolor: "#2f6098",
              cursorwidth: 10,
              cursoropacitymin: 0.7
          });

          $($(this).attr('href')).find("tab-pane").getNiceScroll().show();
      })

      $('#home').find("tab-pane").niceScroll({
          cursorcolor: "#2f6098",
          cursorwidth: 10,
          cursoropacitymin: 0.7
      });
  });
</script>

I've solved this issue on my site with this code.

JS

<script>
         $(document).ready(function() {
                $('a[data-toggle="tab"]').click(function () {
           $(this).closest('.panel').find('.panel-body').niceScroll({
                        cursorcolor: "#2f6098",
                        cursorwidth: 10,
                        cursoropacitymin: 0.7
                    });

           if($(this).attr('aria-controls') == 'profile'){
            $(this).closest('.panel').find('.panel-body').getNiceScroll().show();
           }else{
            $(this).closest('.panel').find('.panel-body').getNiceScroll().hide();
           }
                })
            });
    </script>
user6918973

I have solved this issue on my site with this code. but how can use this code as a plugin, bcoz i get issue in all my web pages.

 $('body').on('click','[data-toggle="tab"]',function(){
     $(".scroll").getNiceScroll().hide();
                  $($(this).attr('href')).find(".scroll").getNiceScroll().show();
 });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!