jQuery-slimScroll icon indicating copy to clipboard operation
jQuery-slimScroll copied to clipboard

How do I change the scroll bar's position programmatically?

Open rubentlz opened this issue 14 years ago • 8 comments

I have a slimScroll plugin attached to an element:

$('#my-element').slimScroll();

And then tried doing this:

$('#my-element').scroll(0, 100);

Doesn't seem to do anything, even though scroll() is a valid function. There is no documentation on how to change the scroll bar's position programmatically, and a look through the github cases doesn't throw any light on this issue. I'm using version 0.5.0.

How do I achieve this? Also, how do I get the current scroll position?

rubentlz avatar Jul 19 '12 08:07 rubentlz

An update, I am able to find the scroll position using scrollTop instead. Should I close this issue?

$('#my-element').scrollTop(); // gives the scroll position
$('#my-element').scrollTop(100); // scrolls vertically to 100px

rubentlz avatar Jul 19 '12 08:07 rubentlz

Hi, you can use:

$('#slimscrolldiv').slimScroll({ scroll: '50px' });

etc

rochal avatar Sep 12 '12 16:09 rochal

Hi Rochal,

Firstly thanks for this great plugin.

I also need this functionality, but nothing I try (scrollBy, scroll, scrollTo) will adjust the scrollbar position - it only scrolls the content.

So if a user hits the 'back to top' button, the scrollbar remains at the bottom. Then if a user tries to use the scrollbar, they jump back to the bottom which is disorienting.

I can update the scrollbar position using CSS top. But I don't know the correct algorithm to adjust it correctly.

Any help would be great,

CJ

cjwebdev avatar Dec 07 '15 01:12 cjwebdev

Any update on this?

I have come across the same problem where I can easily scroll to particular position within scrollable section using scrollTo method but the scrollbar itself still remains in the same position... UX wise is very poor and ideally should be able to figure out if the scrollTo method was called, if so then update the scrollbar position by the same amount of px that we passed to scrollTo method!

I'll take a look at the plugin and see if I could fix it or come up with something, so at least everybody could use it in the future...

Thanks

mrfzd avatar Apr 20 '16 15:04 mrfzd

Hello, same problem here. Did someone find a solution?

paddyfink avatar Apr 25 '16 06:04 paddyfink

@stylishweb I had the same problem and I fixed it like this: this.$('.slimScrollBar').css("top", "YOUR_CUSTOM_HEIGHT_GOES_HERE"); I know it's quite ugly but it works ok..

barteksekula avatar May 10 '16 20:05 barteksekula

Hi all! I had used slimscroll on a table, elements of which appending to it when table scrolled to bottom. So i also had to re-initalize functionary. So this is my solution (re-initalize slimscroll functionality, when table changes)

` var $scroll_wrap = $(element).find('.m-table-o-wrap'); // wrap element var $table = $(element).find('.m-table-wrap'); // wrap content

var current_scrolTop = $scroll_wrap.scrollTop(); var current_height = $table.height(); var scroll_bar_position_top = current_scrolTop/current_height*100+'%';

$scroll_wrap.slimScroll({destroy:true});

$scroll_wrap.slimScroll({ height: '100%', size: '6px', color:'#9B9B9B', opacity:'1', alwaysVisible: true, railVisible: false, });

$(element).find('.slimScrollBar').css("top", scroll_bar_position_top); $scroll_wrap.trigger('mouseover').scrollTop(current_scrolTop); `

Now all works as native system scroll

play0for0fun avatar Jun 25 '16 03:06 play0for0fun

I can't get it work. I have had some height issue when worked on it. My _navbar height is fixing to that pixels. How can I solve it ?

mbsankar84 avatar Apr 02 '19 12:04 mbsankar84