Jquery scroll to offset target div on page load

后端 未结 2 425
感动是毒
感动是毒 2021-01-07 10:20

I\'m trying to scroll to the div that is in the URL. It could be one of 21 IDs like:

url.com/test#lite1

url.com/test#lite2

url.com/test#lite3

2条回答
  •  情话喂你
    2021-01-07 11:01

    As an alternative, you could try using the following jQuery plugins. I've used them on multiple projects. They're customizable and provide nice, smooth animation:

    scrollTo (download, documentation) allows you to scroll to a specific element on the page. Basic usage: $(element).scrollTo(target);

    localScroll (download, documentation) requires scrollTo as a dependency, and handles anchors for you. You can apply it to specific set of links by selecting their container: $('#link-container').localScroll();, or you can activate it globally: $.localScroll();

提交回复
热议问题