Giter VIP home page Giter VIP logo

moobreakpoints's Introduction

MooBreakpoints

A Mootools Plugin for responsive javascript

Media queries are great and can go a long way in shifting your design around depending on the width of the browser window(among other things), but if you back your design up with specific javascript, you will need something to to alert your script that your design is different.

##Backstory A few months ago benbrown created breakpoints for jQuery. I was working on a MooTools project and I needed the breakpoint functionality. So, I took Ben's concept and wrote a moo flavored plugin.

##Example See it in action, take a look at the demo.

##How to Use

#JS
//create an instance of the plugin
myBreakpoints = new MooBreakpoints(/*your options here*/);

//add events - a few breakpoints are baked in, you can set your own in the optiopns
window.addEvents({
                'onWidthEnter480':function() { stuff(); },
                'onWidthLeave480':function() { otherStuff(); }
});

##What kind of options do I have? Four basic options exist - you can see them in action in the example. ###breakPoints Default value - [320, 480, 768, 1024]

This is an array of screen widths that you want to respond to - the number represents the upper end of a range. So, this array:

#JS
[100,200,300]

would respond in three different widths - 0-100 (onWidthEnter100), 101-200 (onWidthEnter200), 201-300 (onWidthEnter300). If you want to fire an event when it is great than a certian width you can use a onWidthLeaveXXX function and test with width in the event.

###delay Default value - 250ms

The events are fired on a self-cancelling timeout so we don't get bogged down in handling every pixel change in width. You can supply any number you want, although I would avoid extremely low numbers.

###delayedResizeEvent Default value - false

Sometimes you just want to know the width of the window. Since this plugin is already measuring it on a self-cancelling timeout, if you set this to true, it will fire onDelayedResize anytime the width of the window changes, even if it isn't a breakpoint. Just a little bonus.

###measureAtDomReady default value - true

This will control if the width of your window is measured after the dom is ready. If it is set to true, your resize events will fire after you have initalized the plugin or when the dom is ready, whichever is last. This gets a little tricky - you will want to setup your onWidthEnterXXX/onWidthLeaveXXX events before you create the instance of the plugin if you want them to immediately fire.

##This is awesome. Where can I find more awesome stuff? You can go to my website (http://stockholmux.com/)

moobreakpoints's People

Contributors

stockholmux avatar

Stargazers

Andy Chentsov avatar  avatar Fabian Vogelsteller avatar Kirk Bentley avatar

Watchers

James Cloos avatar  avatar

moobreakpoints's Issues

Breakpoint sort bug

The break points are not currently being sorted correctly and is causing issues.

this.options.breakPoints.sort() should be something similar to this.options.breakPoints.sort(function(a,b){return a-b});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.