Scroll to an Element Inside a Div


JavaScript • JQuery

Create your container div with id, height, and overflow specified.

<div id="dataContainer" style="height:240px; overflow-y:auto;">
   <div id="scroll-E9DBF2A4A630687487258BC1006F7EDC"></div>
   <div id="scroll-A9B8B5D9794391BC87258BC1006F6F37"></div>
   <div id="scroll-27446C0101AC06A287258BC1006F5A2E"></div>
   <div id="scroll-8C2951823D55B9D387258BC10072ED86"></div>
</div>

Call your function to jump to the specified entry. In this example I'm using docunid of each database document as the unique id key.

$("#dataContainer").animate({
    	scrollTop: $("#scroll-"+docunid ).offset().top - $("#dataContainer").offset().top,
},1000 );

Written by fbrefere001

Posted by fbrefere001 on Monday November 18, 2024