ryanve / response.js

Responsive design toolkit
http://responsejs.com
Other
801 stars 123 forks source link

Pre-determining the current breakpoint on configuration #24

Closed bucha closed 10 years ago

bucha commented 11 years ago

Hi Ryan, in my current project I'm binding quite a lot of logic to the crossover-event and realized, that after the page being loaded, the crossover-event is being fired when resizing the window for some px (but not actually crossing a breakpoint). The problem resides in the Elemset.reset() method

// tempIndex is the index of the breakpoint
// while this.i === 0 initially
if (tempIndex !== this.i) { /* ... */ }

So I added some logic to determine this.i initially inside the configure-method. Maybe I'm doing something wrong here and this is rubbish, but please check my changes. Cheers, Alex

ryanve commented 11 years ago

@bucha Crossover callbacks tend to fire a few pixels away from the actual breakpoint being crossed. It depends on how fast the viewport is resized. See /test, open the console, and resize the window. I'm not sure how initializing this.i helps. Is it just that you need your callback to fire once initially? Perhaps you could initiate via the .ready() and use Response.crossover() for subsequent calls? Please elaborate on your usage so that we can better understand your overall intent. Thanks =]