1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-31 16:51:47 +02:00

Scrolling to current slide when index is shown

This commit is contained in:
Luis
2017-07-14 23:32:15 +02:00
parent 98886a159f
commit c109276ef6
5 changed files with 117 additions and 100 deletions

View File

@@ -1,5 +1,6 @@
import DOM from '../utils/dom';
import Keys from '../utils/keys';
import scrollTo from '../utils/scroll-to';
import Slide from '../modules/slide';
const CLASSES = {
@@ -139,9 +140,9 @@ export default class Zoom {
if (zoomedCurrent) {
zoomedCurrent.classList.remove(CLASSES.CURRENT);
}
this.zws_.el
.querySelector(`#zoomed-${currentId}`)
.classList.add(CLASSES.CURRENT);
const actualCurrent = this.zws_.el
.querySelector(`#zoomed-${currentId}`);
actualCurrent.classList.add(CLASSES.CURRENT);
this.isZoomed_ = true;
document.body.style.overflow = 'auto';
@@ -149,6 +150,9 @@ export default class Zoom {
setTimeout(() => {
this.ws_.disable();
this.zws_.el.classList.add('in');
const wrapCSS = window.getComputedStyle(this.zws_.grid);
scrollTo(actualCurrent.parentNode.offsetTop
+ DOM.parseSize(wrapCSS.paddingTop), 50, () => {}, document.body);
}, 50);
}

View File

@@ -8,9 +8,13 @@ let SCROLLABLE_CONTAINER = null;
* @param {number} y Offset of the page to scroll to.
* @param {number} duration Duration of the animation. 500ms by default.
* @param {function} cb Callback function to call upon completion.
* @param {HTMLElement} container The HTML element where to scroll
*/
export default function scrollTo(y, duration = 500, cb = () => {}) {
if (!SCROLLABLE_CONTAINER) {
export default function scrollTo(y, duration = 500, cb = () => {},
container = null) {
if (container) {
SCROLLABLE_CONTAINER = container;
} else if (!SCROLLABLE_CONTAINER) {
SCROLLABLE_CONTAINER = document.getElementById('webslides');
}