freakydev
freakydev

Reputation: 153

mCustomScrollbar get scroll position

Iam using mCustomScrollbar , I want to know whether my scroll bar position is at bottom using jquery.How is that possible?Can i use ordinary bottom check usage in jquery or any functions are available in the mCustomScrollbar library?

Upvotes: 3

Views: 19296

Answers (3)

Torben
Torben

Reputation: 549

You can calculate scrollTop from dragger's top position:

    var $scrollerOuter  = $( '.mCustomScrollbar' );
    var $dragger        = $scrollerOuter.find( '.mCSB_dragger' );
    var scrollHeight    = $scrollerOuter.find( '.mCSB_container' ).height();
    var draggerTop      = $dragger.position().top;

    var scrollTop = draggerTop / ($scrollerOuter.height() - $dragger.height()) * (scrollHeight - $scrollerOuter.height());

Upvotes: 0

Che
Che

Reputation: 169

I used to myself something like:

$('#someElement').mCustomScrollbar({theme: "minimal"});

and after, you can get scrollTop using this code:

var scrollTop = $('#someElement').find(".mCSB_dragger").position().top;

Upvotes: 4

Gromo
Gromo

Reputation: 1609

Look at callbacks example - there is Scroll percentage that displays % of scrolled. Open HTML source and you will see that it's uses whileScrolling callback: $("#mcs-top-pct").text(this.mcs.topPct+"%");, so when this.mcs.topPct is 100, then container is scrolled to bottom :)

Upvotes: 5

Related Questions