ScrollIntoView() causing the whole page to move

后端 未结 12 2051
庸人自扰
庸人自扰 2020-11-30 21:40

I am using ScrollIntoView() to scroll the highlighted item in a list into view. When I scroll downwards ScrollIntoView(false) works perfectly. But when I scroll upwards, Scr

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 22:14

    jQuery plugin scrollintoview() increases usability

    Instead of default DOM implementation you can use a plugin that animates movement and doesn't have any unwanted effects. Here's the simplest way of using it with defaults:

    $("yourTargetLiSelector").scrollintoview();
    

    Anyway head over to this blog post where you can read all the details and will eventually get you to GitHub source codeof the plugin.

    This plugin automatically searches for the closest scrollable ancestor element and scrolls it so that selected element is inside its visible view port. If the element is already in the view port it doesn't do anything of course.

提交回复
热议问题