From ec80761a5f82da377089ee72e0c1ee11240eb515 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Wed, 2 Jan 2019 00:10:22 +0000 Subject: [PATCH] A hacky delay to scroll page to bottom hopefully after media loads --- webapp/titanembeds/static/js/embed.js | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index ec668f1..e4388b0 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -70,6 +70,19 @@ } } + // https://stackoverflow.com/questions/2956966/javascript-telling-setinterval-to-only-fire-x-amount-of-times + function setIntervalX(callback, delay, repetitions) { + var x = 0; + var intervalID = window.setInterval(function () { + + callback(); + + if (++x === repetitions) { + window.clearInterval(intervalID); + } + }, delay); + } + String.prototype.replaceAll = function(target, replacement) { return this.split(target).join(replacement); }; @@ -1553,14 +1566,18 @@ } else { if (getParameterByName("scrollbartheme")) { if ($(window).height() < $("main .mCSB_container").height()) { - $("main .mCSB_container").animate({ - top: -1 * ($("main .mCSB_container").height() - $(window).height()) - }, "slow", function () { - $("main").mCustomScrollbar("update"); - }); + setIntervalX(function () { + $("main .mCSB_container").animate({ + top: -1 * ($("main .mCSB_container").height() - $(window).height()) + }, "slow", function () { + $("main").mCustomScrollbar("update"); + }); + }, 1000, 3); } } else { - $("main").animate({ scrollTop: $("#chatcontent").height() }, "slow"); + setIntervalX(function () { + $("main").animate({ scrollTop: $("#chatcontent").height() }, "slow"); + }, 1000, 3); } } }