简体   繁体   中英

jQuery scroll content at specific class element

I am using mCustomScrollbar script for custom scroll bar effect now I want to scroll page on specific class element. Class position is not fixed, It can be top or bottom .

In my example I have one anchor link and I want to page scroll to active class. Page will scroll only when user click to anchor.

Here is my JS Code:

$( "#scroll" ).click(function() {
    //scroll page to active class
});

$("#content_1").mCustomScrollbar({
    scrollButtons: {
        enable: true
    }
});

Here is my JSFiddle: http://goo.gl/6dpT7l

Note: Scroll position is not fixed. It can be anywhere UP/Down.

Any Idea? How to do this?

Thanks.

In your fiddle, it seems to be as simple as scrolling to the paragraph in question's position().top attribute. Replace your alert with this:

$("#content_1").mCustomScrollbar('scrollTo', $('.active').position().top);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM