here is my code:
function loadLog() {
var oldscrollHeight = $("#chatbox")[0].scrollHeight - 20; //Scroll height before the request
$.ajax({
url: "log.html",
cache: false,
success: function(html)
{
$("#chatbox").html(html); //Insert chat log into the #chatbox div
//Auto-scroll
var newscrollHeight = $("#chatbox")[0].scrollHeight - 20; //Scroll height after the request
if (newscrollHeight > oldscrollHeight) {
$("#chatbox").animate({
scrollTop: newscrollHeight
}, 'normal'); //Autoscroll to bottom of div
}
}
});
}
setInterval(loadLog, 500);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Is there any option to check, if autoscroll (.animate) is done ?
I want a push notification with push.js. If auto scroll was done, i want to add push:
Push.create("test",{
body: "This is example of Push.js Tutorial",
icon: '/Logo_small.png',
timeout: 2000,
onClick: function () {
window.focus();
this.close();
}
});
You can add a
complete
callback to the.animate()
function:documentation