Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: A way to reinitialize slimScroll after an AJAX Request #14

Closed
joeytheman opened this issue Dec 15, 2011 · 7 comments
Closed

Comments

@joeytheman
Copy link

I have an region that I add and remove items from through ajax requests using slimScroll. When I call slimScroll on the region after additional elements have been added or removed, the region is given additional scrollbars.

As a workaround, I am manually removing the elements added by slimScroll and then calling slimScroll() again.

@rochal
Copy link
Owner

rochal commented Jan 11, 2012

hey joeytheman, can you set up a demo page where this issue is visible?

@tcz
Copy link

tcz commented Apr 26, 2012

This feature would be lovely indeed.

@joeytheman
Copy link
Author

In my case it is not needed. I didn't initially realize the scroller automatically adjusted if additional content was added. Before I discovered this I wrote some code to remove the slim scrol div s and re initialize slim scroll after content was added.

@tcz
Copy link

tcz commented Apr 27, 2012

I need it to adjust the height in case the size of the container changes.

@joeytheman
Copy link
Author

Did you test if the slim scroll automatically adjusts?

If it doesn't here is the function I came up with.

window.activateSlimScroll = function() {
  var height, opts, slimscroll, slimscrolls, t, t_height, _i, _len;
  slimscrolls = $('.newSlimScroll');
  for (_i = 0, _len = slimscrolls.length; _i < _len; _i++) {
      slimscroll = slimscrolls[_i];
  t = $(slimscroll);
  }
  // Check if slimScroll is already activated
  if (t.parent().attr('class') === 'slimScrollDiv') {
      t.unwrap();
  t.parent().find('.slimScrollBar, .slimScrollRail').remove();
  }
 // Activate slimScroll
  t_height = t.height();
  height = t.data('slim-scroll-height');
  opts = {
      height: height,
      start: t.data('slim-scroll-start')
  };
  if (t_height > 250) {
      if (height) {
          if (t_height > height) {
              t.slimScroll(opts);
          }
          } else {
              t.slimScroll(opts);
          }
          }
          return slimscrolls.removeClass('newSlimScroll');
          };

It runs in an ajax:complete callback on elements with the .newSlimScroll class checking for an existing slim scroll and removing it before initializing a new one. Additional options can be set using html5 data attribute.

Let me know if you have any questions or if I can be of any other assistance.

@tcz
Copy link

tcz commented Apr 27, 2012

For what I saw it doesn't really adjust. Also if I call it twice I get two scrollbars.
I'd like to keep all logic related to slimScroll ion the slimScroll library, hence the importance of this this issue to me.

@rochal
Copy link
Owner

rochal commented Mar 14, 2013

from version 1.1.0 onwards slimscroll will recalculate the scrollbar size when you call it again on the same element.

So now, in your ajax callbacks you can simply call: $("#myElement").slimScroll() again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants