javascript mCustomScrollbar“scrollTo”不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11519372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:29:56  来源:igfitidea点击:

mCustomScrollbar "scrollTo" not working

javascriptjquery

提问by Matt

I am using a basic setup for mCustomScrollbar which is working great accept when I call the following:-

我正在使用 mCustomScrollbar 的基本设置,当我调用以下内容时,它工作得很好接受:-

jQuery("#mcs_container").mCustomScrollbar("scrollTo","top");

Nothing happens. There is not error shown in firebug, it just does nothing. Has anyone experienced this before, or does anyone have any idea why this might be happening?

没发生什么事。firebug 中没有显示错误,它什么也不做。有没有人以前经历过这种情况,或者有没有人知道为什么会发生这种情况?

thanks!

谢谢!

回答by varunvlalan

MCustomScrollbar doesn't provide feature of scrolling to top of the page. However, it does support scrolling to specific element in HTML.

MCustomScrollbar 不提供滚动到页面顶部的功能。但是,它确实支持滚动到 HTML 中的特定元素。

For example, if I have an element with id "logout" which is at top of the page and i need to scroll at top, then write

例如,如果我有一个 id 为“logout”的元素位于页面顶部,我需要在顶部滚动,然后写

$("#mcs_container").mCustomScrollbar("scrollTo", "#logout");

Hope you find this useful.

希望您觉得这个有帮助。

Cheers!

干杯!

回答by Salvador Dali

I had the same problem and solved it simply with calculating the position of my first element and scrolling to that number

我遇到了同样的问题,并通过计算我的第一个元素的位置并滚动到该数字来解决它

回答by Ashish Yadav

setTimeout( function () {
   $("#mcs_container").mCustomScrollbar('scrollTo','last');
 }, 100);

Use with time out

超时使用

回答by jeepers_creepers

After searching for a day. Here's what I got:

找了一天之后。这是我得到的:

Tested and working (2019): $('.demo-yx').mCustomScrollbar('scrollTo',['top',null]);

测试和工作(2019): $('.demo-yx').mCustomScrollbar('scrollTo',['top',null]);

From this link. Cheers!

从这个链接。干杯!

回答by mayank gupta

you just need a mCustomScrollbar class..... here is your answer...

你只需要一个 mCustomScrollbar 类......这是你的答案......

$(".scroller-back").mCustomScrollbar("scrollTo",jQuery("#mcs_container"));

$(".scroller-back").mCustomScrollbar("scrollTo",jQuery("#mcs_container"));

回答by Taro Alan

I use like this, it'is working!

我是这样用的,效果很好!

// set scrollbar
$('.scroll-y').mCustomScrollbar({
  theme: 'minimal-dark'
});

// then set scrollTo
$('.scroll-y').mCustomScrollbar('scrollTo', 'bottom');