Operlapping Nicescroll scrolbars in Bootstrap tabs

邮差的信 提交于 2019-12-01 10:53:56

问题


I'm using Nicescroll to display scrollbars on bootstrap tabs.

While it displays the scrollbars, if we initialize nicescroll on multiple tabs, the scroller from non-active tabs are also visible at all times.

This fiddle is a recreation of the issue: http://jsfiddle.net/LittleLebowski/B86me/15/ Here's the code: HTML code

<!-- Nav tabs -->
<ul class="nav nav-tabs">
  <li><a href="#home" data-toggle="tab">Home</a></li>
  <li><a href="#profile" data-toggle="tab">Profile</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="home">
      <div class="scroller" data-height="150px">
          <p>Tight pants next level keffiyeh you probably haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown. Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel have a terry richardson vinyl chambra</p><br><br><p>y. Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. A really ironic artisan whatever keytar, scenester farm-to-table banksy Austin twitter handle freegan cred raw denim singl</p><br><br><p>e-origin coffee viral.
          </p></div>
    </div>

  <div class="tab-pane" id="profile">
       <div class="scroller" data-height="150px">
           <p>In July 1978, Post-Newsweek exchanged WTOP-TV with the Evening News Association's WWJ-TV (now WDIV-TV) in Detroit. Upon completion of the swap, WTOP-TV changed its ca</p><br><br><p>ll letters to WDVM-TV, with the new call letters representing the initials of the areas which channel 9 serves: District of Columbia, Virginia and Maryland. Post-Newsweek parent The Washington Post Company, and the Evening News Association, which publi</p><p>shed the Detroit News, decided to swap their stations for fear that the FCC would force them to sell the stations at unfavorable terms or revoke their very valuable </p><br><br><p>licenses because the FCC at the time was considering forbidding ownership of newspapers and broadcast stations in the same market</p>
      </div>
      </div>
</div>

JS code

$(document).ready(
    function() {
        $('.scroller').each(function () {
            $(this).height($(this).attr("data-height"));
            $(this).niceScroll({
                cursorwidth: '7px',
                cursorcolor: '#A1B2BD',
                cursoropacitymax: 0.6,
                autohidemode: false 
            });
        });
    }
  );

How can I show scrollbars only on the active tabs.

Kindly guide me. :(


回答1:


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>



回答2:


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>



回答3:


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


来源:https://stackoverflow.com/questions/20094873/operlapping-nicescroll-scrolbars-in-bootstrap-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!