[英]Scroll to element if it not in viewport
jScrollPane library have a scrollToElement
method which can scroll to element if it not in viewport. jScrollPane库有一个
scrollToElement
方法,如果它不在视口中,则可以滚动到该元素。
Also this method have a stickToTop
parameter which scroll as little as possible to show the element (not top of the viewport, like it do scrollTop
). 此方法还具有一个
stickToTop
参数,该参数会尽可能少地滚动以显示该元素(而不是视口的顶部,就像scrollTop
)。
Anyone knows standalone plugin for that functionality? 有人知道该功能的独立插件吗? Or how it can be realised in JS (I'm not an expert in JS and I can't extract this function from jScrollPane).
或如何在JS中实现它(我不是JS专家,我无法从jScrollPane提取此函数)。
Yuu should user scrollIntoView(true)
function. 您应该使用
scrollIntoView(true)
函数。
https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.