Home >Web Front-end >JS Tutorial >Scroll the DIV scroll bar to the specified position through JQuery to facilitate automatic positioning_jquery

Scroll the DIV scroll bar to the specified position through JQuery to facilitate automatic positioning_jquery

WBOY
WBOYOriginal
2016-05-16 16:49:491314browse

Here is a method to scroll the DIV's scroll bar to the location of its child elements to facilitate automatic positioning.

Copy code The code is as follows:

var container = $('div'),
scrollTo = $('#row_8');

container.scrollTop(
scrollTo.offset().top - container.offset().top container.scrollTop()
);

// Or you can animate the scrolling:
container.animate({
scrollTop: scrollTo.offset().top - container.offset().top container.scrollTop()
});​

You don’t need any JQuery plug-in to achieve the desired effect, it’s very easy to use!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn