I have this situation in which I need to scroll an element into the viewport. The problem is that I don\'t know which element is scrollable. For example, in Portrait the bod
If you are using jQuery UI you can use the scrollParent
method. Have a look at the API or the source.
From the API:
.scrollParent()
: Get the closest ancestor element that is scrollableThis method does not accept any arguments. This method finds the nearest ancestor that allows scrolling. In other words, the
.scrollParent()
method finds the element that the currently selected element will scroll within.Note: This method only works on jQuery objects containing one element.
If you are not using jQuery UI but are using jQuery, then there are alternative independent libraries providing similar functionality, such as:
jquery-scrollparent
This is the way to find what you want.
document.addEventListener('scroll', (e) => {
console.log(e.target.scrollingElement.scrollTop);
})