lukehaas / Scrollify

A jQuery plugin that assists scrolling and snaps to sections.
MIT License
1.81k stars 577 forks source link

Scrollify.destroy doesn't get rid of the fixed height #261

Open abdi-saeed opened 7 years ago

abdi-saeed commented 7 years ago

The goal: small/mobile breakpoint, I would like to destroy scrollify. On wide screen/desktop, I would like to . use scrollify functionality.

Issue: On "mobile", scrollify is destroyed (normal scroll behaviour). But the height initially is changed to auto then very quickly to the viewport height. Am not sure what's forcing this. I have tried to simplify the code as much as possible and used native JS instead of EnquireJS I was using initially.

var $body = $("body");
var mqMobile = window.matchMedia("screen and (max-width : 1023px");
mqMobile.addListener(mobileView);
function mobileView(mqMobile) {
  if (mqMobile.matches) {
    console.log("Mobile: match");
    $body.addClass("mobile").removeClass("desktop");
    $.scrollify.destroy();
    $(".slide").attr("style", "height: auto");
  } else {
    console.log("Desktop: match");
    $body.addClass("desktop").removeClass("mobile");

    $.scrollify({
      section : ".slide"
    });
  }
}
mobileView(mqMobile);
lukehaas commented 7 years ago

Try setting setHeights to false.

abdi-saeed commented 7 years ago

Where should this option be set? on $.scrollify() or $.scrollify.destroy()???? To be clear, this issue am experiencing (where scrollify is killed for small screens and scroll is back to normal but the height changes momentarily to auto and goes back full page) ONLY happens when am resizing the window. On page reload, things work as expected.

ghost commented 6 years ago

I'm also getting this same experience. On resize and below a certain width destroy() does not fire

pmioni commented 6 years ago

In my case, destroy DOES fire and sets height of the slides to "auto", but then something else intervenes and redoes the height calculation.

pmioni commented 6 years ago

If you start scrollify like this: $.scrollify({ section: ".lm-page .lm-page__slide", setHeights: false }) then heights won't be set (but you have to set them in your own CSS with vh units, for example. In this case it all works.

But I still think there's a bug where destroy does set the height of the slides to "auto", but then some other function gets called and sets them again.