From b996e013ee7db14988f7ae50bae9efe0d09da27a Mon Sep 17 00:00:00 2001 From: eAlasdair Date: Mon, 7 Sep 2020 12:48:22 +1200 Subject: [PATCH] fix bug in tutorial where elements weren't scrolled to properly --- codewof/static/js/question_types/base.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/codewof/static/js/question_types/base.js b/codewof/static/js/question_types/base.js index 91b4e93fc..2ed025202 100644 --- a/codewof/static/js/question_types/base.js +++ b/codewof/static/js/question_types/base.js @@ -133,13 +133,15 @@ function scroll_to_element(containerId, element) { // For use by the tutorials var container = $('#' + containerId); var contWidth = container.width(); - var elemLeft = $(element).offset().left - container.offset().left; + var contLeft = container.offset().left; + var elemLeft = $(element).offset().left - contLeft; // wrt container var elemWidth = element.width(); - var isInView = (elemLeft >= 0 && ((elemLeft + elemWidth) <= contWidth)); + var isInView = elemLeft >= 0 && (elemLeft + elemWidth) <= contWidth; if (!isInView) { - var scrollLeftValue = element.offset().left; - container.scrollLeft(scrollLeftValue); + container.scrollLeft(0); + var scrollTo = $(element).offset().left - contLeft; + container.scrollLeft(scrollTo); } }