8000 When resizing quickly, events don't fire for intermediate breakpoints · Issue #19 · tdreyno/morlock.js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 1, 2020. It is now read-only.

When resizing quickly, events don't fire for intermediate breakpoints #19

Open
chrisforrette opened this issue Mar 13, 2015 · 1 comment

Comments

@chrisforrette
Copy link
Contributor
chrisforrette 8356 commented Mar 13, 2015

I have breakpoints that look like:

{
  breakpoints: {
    small: {
      min: 480
    },
    medium: {
      min: 680
    },
    large: {
      min: 900
    },
    xlarge: {
      min: 1220
    }
  }
}

And, using the $(window).morlockBreakpoint(), and sizing quickly from small to xlarge, I would expect "enter" breakpoint events to fire for medium, large, and xlarge, but that doesn't happen.

@tdreyno
Copy link
Owner
tdreyno commented Mar 14, 2015

There is a throttle on the resize listener. Decreasing it to 0 would probably have the effect you want, at the cost of performance.

Alternatively, if you need the intermediate breakpoints you could:

var breaks = ['small', 'medium', 'large', 'xlarge'];

function enter(bp) {
  // do something
}

$(window).morlockBreakpoint({
  breakpoints: {
    small: {
      min: 480
    },
    medium: {
      min: 680
    },
    large: {
      min: 900
    },
    xlarge: {
      min: 1220
    }
  }
});

var currentBP;
$(window).on('morlockBreakpoint', function(e, b) {
  if (currentBP && (currentBP !== b)) {
    var cIdx = breaks.indexOf(currentBP);
    var nIdx = breaks.indexOf(b);
    var direction = nIdx > cIdx ? +1 : -1;

    var i = cIdx + direction;
    do {
      enter(breaks[i]);
    } while(i !== nIdx);
  }

  currentBP = b;
});

Or, maybe this is a bug, I'll check :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0