Tuesday 15 June 2010

jquery - Chat scroll won't go down, upon new message? -


When a new message occurs, the scroll just goes up, while I have a method Drag it down, if at its bottom:

  element = $ ("# chat") [0]; If (element.scrollTop == element.scrollHeight - element.height) {element.scrollTop (element.scrollHyight); }   

While running this interval:

  setInterval (function () {pingServer (); element = $ ("# chat") [0] ; If (element.scrollTop == element.scrollHeight - element.height) {element.scrollTop (element.scrollHyight);}}, 5000);   

Earlier used to work, I was not sure why this work stopped now.

Why stopped any thoughts? > function reload () {$ .post ("ajax.php", {loadMessages: "1"}, function (data) {$ (" Html (data) element = $ ("# chat") [0]; if (element.scrollTop == element.scrollHeight - element.height) {element.scrollTop (element.scrollHeight);}}) ; }

reload the function

Your ping work on the server Asynchronous, and you are not calling your logic to adjust the scrolling position on the call back of this request.

Therefore, as long as your ping does not react instantly, your process is flowing:

  • < / Li>

  • > So you need to adjust your call back in your call, where you add new messages Are there.

    Why did any thoughts stop?

    My guess is that the response to your server is taking longer (perhaps you have moved to a production environment) and therefore your process flow is out of sync.

No comments:

Post a Comment