I'm struggling with ensuring that the Segment is scrolled to the bottom. I read up a lot on Stack Overflow about how we have the scrollTop
attribute in CSS as well as the scrollTop()
function with jQuery. I'm copying here the relevant code I was able to find:
Heads up: I'm using React and Semantic UI react if that makes a difference. Also, I've just installed jQuery via npm to try to use the solutions I found online.
This is my Div:
<Segment id="myDivID" style={{minHeight:"450px",maxHeight:"450px", "overflow-y":"auto", "scrollTop":"450px"}} >
// all of the individual chat messages
</Segment>
and here is the styling I'm trying to use in addition to the scrollTop
attribute in the style passed above.
useEffect(()=>{
var element = document.getElementById("myDivID");
if(element){
window.scrollTo(0,element.offsetHeight);
}
},[])
$('#myDivID').scrollTop($('#myDivID').scrollHeight);