How do I get an element to scroll into view, using jQuery?

后端 未结 11 1393
夕颜
夕颜 2020-11-28 19:31

I have an HTML document with images in a grid format using

  • . The browser window has both vertical & horizontal scrolling.

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 20:23

    Here's a quick jQuery plugin to map the built in browser functionality nicely:

    $.fn.ensureVisible = function () { $(this).each(function () { $(this)[0].scrollIntoView(); }); };
    
    ...
    
    $('.my-elements').ensureVisible();
    

提交回复
热议问题