From 84e715d4802a2ca71ddcd5bca47099f448df6fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 18 Oct 2018 12:51:12 +0200 Subject: [PATCH] fix not starting out scrolled down --- main.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index d664656..5662a8e 100644 --- a/main.js +++ b/main.js @@ -48,7 +48,7 @@ document.querySelector('.form__input-submit').addEventListener('click', function function getMessages() { const timestamp = (document.querySelector('.chat').lastElementChild) ? document.querySelector('.chat').lastElementChild.getAttribute('data-timestamp') : 0 - fetch('api.php?action=getMessages×tamp=' + timestamp) + return fetch('api.php?action=getMessages×tamp=' + timestamp) .then(function (data) { return data.json() }) @@ -106,7 +106,10 @@ function createMessageNode(name, text, timestamp, datetime) { return true } -getMessages() +getMessages().then(() => { + scrollWindowDown() +}) + setInterval(function () { getMessages() }, 2000)