1

I used the answer to this question to auto-scroll a combat log for my HTML5 game to the bottom:

How to auto-scroll to end of div when data is added?

If I want to briefly disable this while a person clicks to scroll up and view the log, how would I do so?

The Code I'm using is:

//autoscroll combat log

window.setInterval(function() {
  var elem = document.getElementById('log');
  elem.scrollTop = elem.scrollHeight;
}, 500);

Best regards, Cobwebs

Edit: the code above is connected to a simple span in a div:

<div>
    <span id='log'></span>
</div>

Stylized to have a scrollbar:

span#log {

    display: block;
    font-family: courier, sans;
    margin: auto;
    border:1px solid black;
    width:600px;
    height:200px;
    overflow:auto;
    background-color:black;
    color: lime;
    text-align: left;

}
Community
  • 1
  • 1
cobwebs
  • 13
  • 3

1 Answers1

0

setInterval() returns an ID, with that ID you can use clearInterval() to stop it

var intervalID = window.setInterval(function() {
  var elem = document.getElementById('log');
  elem.scrollTop = elem.scrollHeight;
}, 500);

and then this

window.clearInterval(intervalID);

small DEMO

Juan
  • 4,910
  • 3
  • 37
  • 46