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

后端 未结 11 1421
夕颜
夕颜 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条回答
  •  猫巷女王i
    2020-11-28 20:12

    Simplest solution I have seen

    var offset = $("#target-element").offset();
    $('html, body').animate({
        scrollTop: offset.top,
        scrollLeft: offset.left
    }, 1000);
    

    Tutorial Here

提交回复
热议问题