Skip to content Skip to sidebar Skip to footer

Jquery Scroll Li Id To Top Of Div

I am using JQuery to scroll a selected list item into view within a div where the overflow is set to scroll. The following code works OK but it scrolls the selected list item to th

Solution 1:

See the code below. Hope this will be helpful for you.

var container = $('#QuestionScroller'),
    scrollTo = $('#ListItemQuestion');
    container.animate({scrollTop: scrollTo.offset().top - container.offset().top + 
                       container.scrollTop()});
#QuestionScroller {
    width: 200px;
    height: 70px;
    border: 1px solid blue;
    overflow: auto;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="QuestionScroller"><ul><liid='row_1'>111111</li><liid='row_2'>222222</li><liid='row_3'>333333</li><liid='ListItemQuestion'>444444</li><liid='row_5'>555555</li><liid='row_6'>666666</li><liid='row_7'>777777</li><liid='row_8'>888888</li><liid='row_9'>999999</li></ul></div>

Solution 2:

You can do like this $("body").animate({scrollTop:$(“##QuestionScroller”).offset().top},2500) can it work?

Post a Comment for "Jquery Scroll Li Id To Top Of Div"