0

I'm using a custom scrollbar plugin called Tiny Scrollbar. Inside the scrollbar I have an accordion type navigation.

My problem is the scrollbar doesn't update when the navigation height is changed, anyone got any ideas? I'm thinking maybe some form of ajax update on every click, however I have no experience in ajax so I don't know. This is the code for the navigation.

<div id="nav-container">
  <div class="scrollbar">
    <div class="track">
      <div class="thumb">
        <div class="end"></div>
      </div>
    </div>
  </div>
<div class="viewport">
  <div class="overview">
    <nav class="main">

    <div class="menu-item">
      <h4><a href="#">Inledning</a></h4>
        <ul>
          <li><a href="#">Link 1</a></li>
          <li><a href="#">Link 2</a></li>
          <li><a href="#">Link 3</a></li>
        </ul>
    </div>

    </nav>
  </div>
</div>
</div>

jQuery:

$(document).ready(function() {
var $ul = $('ul');

$( "h4" ).click(function() {
  $( "h4" ).removeClass( "menu-selected" );
  $ul.hide( "blind", 1000 );
$(this).toggleClass( "menu-selected" );
  $(this).next().show( "blind", 1000 );
});

$( "li" ).click(function() {
  $( "li" ).removeClass( "select" );
    $(this).addClass( "select" );
  });
});
2
  • Have you looked at the tiny scrollbar's update method tinyscrollbar_update()? Commented Feb 2, 2013 at 19:47
  • 1
    Oh and AJAX you would only use when adding content from an external file or page, you don't need to use it here. Commented Feb 2, 2013 at 20:08

1 Answer 1

1

On the Tiny Scrollbar website it says that when new content is added you need to update the holding container. e.g.

//The update method can be used for adjusting a scrollbar to its new content.
var yourScrollBar = $('nav-container');
yourScrollBar.tinyscrollbar();

//The below function would be called when updating the content. 
yourScrollBar.tinyscrollbar_update();

The above code is an example from the plugin website.

For example with your code.

$( "h4" ).click(function() {
  $( "h4" ).removeClass( "menu-selected" );
  $ul.hide( "blind", 1000 );
  $(this).toggleClass( "menu-selected" );
  $(this).next().show( "blind", 1000 );
  yourScrollBar.tinyscrollbar_update(); <-------- Here. 
});
Sign up to request clarification or add additional context in comments.

5 Comments

Can't get this to work, tried putting the var yourScrollBar both outside and inside document ready, and the _update is exactly where u put it. But nothing happens. :/
The var yourScrollBar bit is just to declare a new scroll bar... you should have already done this to get it work in the first place? And the only bit you need to add is the **YourDeclaredScrollBar**.tinyscrollbar_update(); to the click function.
I could be wrong about this though :) Have a read of the site this is where I got the update bit from.
Nah I used $('nav-container'), tried changing it to that now and it updates the scrollbar, wierd how it didn't do it with the variable though. It doesn't work perfect yet I have some stuff to figure out. Thanks for the help. =)
No problem glad to have helped in some way :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.