return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>html - Pure Javascript - Click and scroll to Div inside div - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Pure Javascript - Click and scroll to Div inside div - Stack Overflow

programmeradmin2浏览0评论

I have the following HTML, with scrollbar:

<div id="parent">
      <div id="child1">Something</div>
      <div id="child2">Something</div>
      <div id="child3">Something</div>
      <div id="child4">Something</div>
      <div id="child5">Something</div>
      <div id="child6">Something</div>
      <div id="child7">Something</div>
      <div id="child8">Something</div>
      <div id="child9">Something</div>   
</div>

My question is this:

How can I, in pure javascript, position the scroll of the div 'parent' in one of the childs?

I have the following HTML, with scrollbar:

<div id="parent">
      <div id="child1">Something</div>
      <div id="child2">Something</div>
      <div id="child3">Something</div>
      <div id="child4">Something</div>
      <div id="child5">Something</div>
      <div id="child6">Something</div>
      <div id="child7">Something</div>
      <div id="child8">Something</div>
      <div id="child9">Something</div>   
</div>

My question is this:

How can I, in pure javascript, position the scroll of the div 'parent' in one of the childs?

Share Improve this question asked Jul 5, 2017 at 16:03 Nuno RibeiroNuno Ribeiro 2,5652 gold badges27 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You can use the scrollIntoView function of JavaScript like this:

document.getElementById('child9').scrollIntoView()

Try it online

发布评论

评论列表(0)

  1. 暂无评论