MCustomScrollBar "scrollTo, divID" does not work

I seem to have problems scrolling an element using the .mCustomScrollbar ("scrollTo", divID) function.

I have a div (id = "# wrapper") containing many divs (anything up to 800 divs heights each 20px).

Then I add mCustomScrollbar to this #wrapper div to use my own scroll functions this way:

$("#wrapper").mCustomScrollbar();

Now I have a large scrollable div containing a โ€œlist-likeโ€ divs structure, not the actual list, but only divs stacked on top of each other, like a list.

Elsewhere on my page, I have a button containing the div element identifier inside the "#wrapper" div, when I click this button, I want to scroll the div element in the view, this is my current attempt:

var divID = 'div[id^=' + clickedID +']';

$('#wrapper').mCustomScrollbar("scrollTo",divID);

This function claims to scroll through the "divID" in the form in the #wrapper div and however the problem is that it sometimes takes 2-4 to call the "scrollTo" function before the "divID" appears.

Can someone please help me understand why the โ€œdivIDโ€ is not looking at the appearance of the first call to the โ€œscrollToโ€ function and how can I make it work as I expect?

Yours faithfully

+4
source share
1 answer

I know I'm a little late, but maybe I can help you (or someone here) ...

. ( ) , .

:

var objPixelScrollIntoView = $('#myObjToScrollIntoView')[0].offsetTop;
$('#myDivSetWith_mCustomScrollbar').mCustomScrollbar("scrollTo", objPixelScrollIntoView);

, , :

var objDivPosition = $('div#' + clickedID)[0].offsetTop;  // The 'div' before '#' is not necessary, but I want to keep some reference to Your selector
$('#wrapper').mCustomScrollbar("scrollTo", objDivPosition);
+4

Source: https://habr.com/ru/post/1525327/


All Articles