Scroll to a specific div

前端 未结 5 717
猫巷女王i
猫巷女王i 2021-01-19 00:44

I have few divs .posts which have a attr data-id which corresponds to the mysql DB id.

5条回答
  •  囚心锁ツ
    2021-01-19 01:08

    You can use jQuery.ScrollTo plugin: https://github.com/flesler/jquery.scrollTo

    In this link you can find demos http://demos.flesler.com/jquery/scrollTo/

    $(function() {             
        $('body').scrollTo($('div[data-id=1]'), 1000); //scroll to div 1        
    });
    

    HTML:

提交回复
热议问题