![](/img/trans.png)
[英]How to scroll to an element with a specific class inside a modal using jquery?
[英]jQuery scroll content at specific class element
我现在使用mCustomScrollbar脚本自定义滚动条效果,我想在特定类元素上滚动页面。 班级位置不是固定的,可以是top
或bottom
。
在我的示例中,我有一个锚链接,并且我想将页面滚动到active
类。 仅当用户click
锚定时页面才会滚动。
这是我的JS代码:
$( "#scroll" ).click(function() {
//scroll page to active class
});
$("#content_1").mCustomScrollbar({
scrollButtons: {
enable: true
}
});
这是我的JSFiddle: http : //goo.gl/6dpT7l
注意:滚动位置不固定。 它可以在上/下任意位置。
任何想法? 这个怎么做?
谢谢。
在您的小提琴中,这似乎很简单,只需滚动到相关问题的position()。top属性中的段落即可。 以此替换警报:
$("#content_1").mCustomScrollbar('scrollTo', $('.active').position().top);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.