I have a chat box where people will beable to add there own message to it but my problem is that when new messages are added it does not scroll down to reveal the new message. I fixed this by using this code
$('.panel-body').scrollTop($('.panel-body').height()*$('.panel-body').height());
(panel-body is the class of my scrolling div)
But the problem with this is that if a user wants to scroll back up at previous messages he or she will be forced back down to the bottom. What would be the best way to stop "auto scrolling" when the user scrolls but when the user scrolls back down or just loads the page it would start up again.
function addMsg(is_admin, name, mes, time) {
var newDiv = document.createElement("div");
newDiv.className = "row";
var p = document.createElement("p");
p.className = "text-muted name";
var p2 = document.createElement("p");
var text = document.getElementById("start");
var hr = document.createElement("hr");
var times = document.createElement("p")
text.appendChild(newDiv);
newDiv.appendChild(p);
p.innerHTML = name + ":";
newDiv.appendChild(p2);
newDiv.appendChild(times)
times.className = "time";
if (is_admin) {
p.style = "color: red;";
p2.innerHTML = mes;
times.innerHTML = "time: " + time;
} else {
p2.innerHTML = mes;
times.innerHTML = time;
}
newDiv.appendChild(hr);
This is my addMsg Function that i have already created