jQuery 将元素滚动到可视区域


#博客


方式1:offset() + scrollTop()

先定位元素位置,然后进行滚动操作:

var top = $("#element").offset().top;
$(window).scrollTop()

效果待验证,细节上可能有问题。

方式2:scrollintoview 插件

使用插件: https://github.com/litera/jquery-scrollintoview

方式3:JS 自带的 scrollIntoView 函数

参考:https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView



( 本文完 )