Skip to content

Commit

Permalink
fix bug in tutorial where elements weren't scrolled to properly
Browse files Browse the repository at this point in the history
  • Loading branch information
eAlasdair committed Sep 7, 2020
1 parent d697f7b commit b996e01
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions codewof/static/js/question_types/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b996e01

Please sign in to comment.