Skip to content

Commit

Permalink
Merge pull request #303 from uccser/issue/51
Browse files Browse the repository at this point in the history
Fix bug in page helpers where elements weren't scrolled to properly
  • Loading branch information
eAlasdair authored Sep 7, 2020
2 parents 4353521 + b996e01 commit 7b0baf3
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 7b0baf3

Please sign in to comment.