JSFiddle - React, Tailwind, and code Playground

by skram

HTML

<div id="scrollingDiv">
    Test<br />
    Test<br />
    Test<br />
    Test<br />
    Test<br />
    Test<br />
    Test<br />
    Test<br /> 
    Test<br />
    Test<br />
    Test<br />
    Test<br />
    Test<br />
    Test<br />
    Test<br />
    Test<br />    
</div>

CSS

#scrollingDiv {
    height: 150px;
    width: 170px;
    overflow: auto;
    border: 1px dashed #EBC211;
}

JavaScript

var isScrolling = false;
var lastScrollPos = 0;
var counter = 0;
$(function() {

    $('#scrollingDiv').on('scroll', function() {
        isScrolling = true;
        lastScrollPos = this.scrollTop;
    });


    refreshTimer = setInterval(refreshContent, 5000);

    function refreshContent() {
        if (!isScrolling) {
            $('#scrollingDiv').html('Latest Test Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />Latest Content <br />').scrollTop(lastScrollPos);
            
            //set scroll position
            
            //$('#leftside div#alerts_wrapper').load('staffhome.php #alerts_container');            
        }
        isScrolling = false;
    }

});