jQuery scrollTop() does not work in scrolling DIV on mobile browsers, alternatives?

前端 未结 13 1027
傲寒
傲寒 2020-12-08 19:52

I am trying to scroll to a specific location in a scrolling DIV. Right now I am using a pixel offset with the jQuery scrollTop() function which works great on desktop brows

13条回答
  •  醉话见心
    2020-12-08 20:15

    rather than using the scroll, scrollTo, or scrollTop methods (which give me problems in mobile), I recommend setting an ID on your top DOM element (like #top), and just using:

    document.getElementById("top").scrollIntoView();
    

    that works the best for me so far across all devices and browsers.

提交回复
热议问题