Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on resize lory bug #237

Closed
jinkwon opened this issue Mar 15, 2016 · 5 comments · Fixed by #401
Closed

on resize lory bug #237

jinkwon opened this issue Mar 15, 2016 · 5 comments · Fixed by #401

Comments

@jinkwon
Copy link

jinkwon commented Mar 15, 2016

Hi lory.
First of all, Thanks good lib.
I found some issue in lory.

I moved to 3rd panel, and then I tried to resize window.
And bug appeared in here, lory panel go to 1st panel.

So, I tried such as code.
But I think it should be default.
Can you give me some advice?

Thanks for your effort.

// persist panel index
elFlick.addEventListener('on.lory.resize', (e) => {
    this.flicking.slideTo(this.currentFlickingIndex);
});
@jinkwon jinkwon changed the title on resize lory on resize lory bug Mar 15, 2016
@davehax
Copy link

davehax commented May 7, 2016

Hi Jinkwon,

Recently for a project i modified the distributed "Lory.js" file to maintain the current slide index on window resize. Unfortunately i'm unsure on how to contribute this to the source files.
Here are the relevant functions:

function reset(persistIndex) {
    var _options5 = options;
    var infinite = _options5.infinite;
    var ease = persistIndex === true ? null : _options5.ease;
    var rewindSpeed = persistIndex === true ? 0 : _options5.rewindSpeed;

    slidesWidth = slideContainer.getBoundingClientRect().width || slideContainer.offsetWidth;
    frameWidth = frame.getBoundingClientRect().width || frame.offsetWidth;

    if (frameWidth === slidesWidth) {
        slidesWidth = slides.reduce(function (previousValue, slide) {
            return previousValue + slide.getBoundingClientRect().width || slide.offsetWidth;
        }, 0);
    }

    if (persistIndex !== true) {
        index = 0;
    }

    if (infinite) {
        translate(slides[index + infinite].offsetLeft * -1, 0, null);

        index = index + infinite;
        position.x = slides[index].offsetLeft * -1;
    } else {
        translate(slides[index].offsetLeft * -1, rewindSpeed, ease);
        position.x = slides[index].offsetLeft * -1;
    }
}
function onResize(event) {
    reset(true);

    dispatchSliderEvent('on', 'resize', {
        event: event
    });
}

@nstanard
Copy link
Collaborator

nstanard commented Jun 1, 2016

I'll work on this if it's alright!

@riotcku
Copy link

riotcku commented Jun 22, 2016

I made an option to change this behavior in this PR: #312

@dduskim
Copy link
Contributor

dduskim commented Jul 15, 2016

👍

@rekateka
Copy link

rekateka commented Aug 24, 2016

I only just noticed this behaviour, not by actually, well, resizing the browser window but instead by scrolling/swiping up and down a page in Safari on an iPad, causing the address bar (and subsequently the window) to resize. That might be a little be confusing for the user so I have a not-so-elegant solution for now:

const carousel = document.querySelectorAll('.carousel')[0];
let activeSlide = 0;

const loryInstance = lory(carousel, {
  infinite: 1,
  enableMouseEvents: true
});

carousel.addEventListener('after.lory.slide', () => {
  activeSlide = loryInstance.returnIndex();
});

carousel.addEventListener('on.lory.resize', () => {
   loryInstance.slideTo(activeSlide); //the default slide duration makes the transition back to the active slide very obvious
});

Ideally it'd be great if this behaviour could be disabled altogether or trigger the reset only when the browser width changes, not both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants