search

Home  >  Q&A  >  body text

javascript - How to set the initial position of overflow scroll?

Usetop: 50%; transform: translateY(-50%)Vertically centered p
When the height of p is greater than the parent container, the initial position of the scroll is not the top of the p
Similar to this, please give me some advice. .

phpcn_u1582phpcn_u15822785 days ago805

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:18:30

    $('body').scrollTop(200); // 滚动到离顶部 200 的地方 
    $('body').scrollTop($('body')[0].scrollTop); // 滚动到底部 

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:18:30

    $('body').scrollTop(‘(current center element height - container height)/2’); Remember to add if height is not greater than the judgment

    reply
    0
  • Cancelreply