Commit 0de45814 by Matjaz Gregoric

Make sure only one scroll animation gets queued/run.

The scrollIntoView function can be called multiple times,
which resulted in multiple (10+) scroll animations getting queued.

After the first animation successfully scrolled to the top of the step,
the others kept running one by one. The animations weren't visible
because the element was already scrolled to its final position, but if
you tried manually scrolling down while the animations were still running,
the window would be scrolled right back up.
parent d4682f28
...@@ -387,9 +387,16 @@ function MentoringWithStepsBlock(runtime, element) { ...@@ -387,9 +387,16 @@ function MentoringWithStepsBlock(runtime, element) {
} }
function scrollIntoView() { function scrollIntoView() {
// This function can be called multiple times per step initialization.
// We must make sure that only one animation is queued or running at any given time,
// that's why we use a special animation queue and make sure to .stop() any running/queued
// animations before enqueueing a new one.
var rootBlock = $(element), var rootBlock = $(element),
rootBlockOffset = rootBlock.offset().top; rootBlockOffset = rootBlock.offset().top,
$('html, body').animate({ scrollTop: rootBlockOffset }, 500); queue = 'sb-scroll',
props = {scrollTop: rootBlockOffset},
opts = {duration: 500, queue: queue};
$('html, body').stop(queue, true).animate(props, opts).dequeue(queue);
} }
function initClickHandlers() { function initClickHandlers() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment