diff --git a/rocketc/static/js/src/rocketc.js b/rocketc/static/js/src/rocketc.js index 6a4ffc62..296879e4 100644 --- a/rocketc/static/js/src/rocketc.js +++ b/rocketc/static/js/src/rocketc.js @@ -51,9 +51,15 @@ function RocketChatXBlock(runtime, element) { loadGroups(); } else { $("#myframe").on("load", function() { - $("#myframe").hide(); - setTimeout(function(){ $("#myframe").show(); }, 2000); + if (!isScrolledIntoView($(".rocketc_block"))) { + $("#myframe").hide(); + } }); + window.onscroll = function() { + if (isScrolledIntoView($(".rocketc_block"))) { + $("#myframe").show(); + } + }; } $("#button", element).click(function(eventObject) { @@ -154,4 +160,14 @@ function RocketChatXBlock(runtime, element) { }) }; + function isScrolledIntoView(elem){ + var docViewTop = $(window).scrollTop(); + var docViewBottom = docViewTop + $(window).height(); + + var elemTop = $(elem).offset().top; + var elemBottom = elemTop + $(elem).height(); + + return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop)); + }; + }