GithubHelp home page GithubHelp logo

siathalysedi / breakpoint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joshuabambrick/breakpoint

0.0 3.0 0.0 143 KB

Provides a jQuery method to call callbacks on customisable breakpoints for responsive web apps.

breakpoint's Introduction

jQuery breakpoint 0.0.1

A simple jQuery plugin which allows you to set callbacks to be called on customisable breakpoints when certain breakpoints are entered an exited. Providing a flexible way to make fully responsive web apps.

Introduction

$.breakpoint.on(toMatch, callback, [callNow], [altBreakpoints])

To set a callback to be run on a breakpoint, call $.breakpoint.on, it returns the current matched breakpoint (see toMatch below)

The first parameter, toMatch, is an array of the names of the breakpoints which, when entered/exited the callback should be called.

The second parameter, callback, is the callback which should be called.

The third parameter, callNow, is optional, and provides a way to automatically call callback, passing the name of the breakpoint that is currently matched - note that this will not work unless the page has been rendered at the time of calling.

The fourth parameter, altBreakpoints, is optional and provides a way to override the breakpoints which should be used with this particular callback - it will not affect any other callbacks that you set. For information about the format of this parameter, see $.breakpoint.changeBreakpoints below.

The callback receives the name of the first breakpoint matched in the toMatch array, if no breakpoint was matched (in the case that one of these breakpoints was left), then this will be 'default'. In addition, the breakpoint matched at the time of calling is returned from every call to $.breakpoint.on.

var makeChanges = function (breakpointName) {
    if (breakpointName === 'palm') {
        // make changes for mobile
    } else if (breakpointName === 'lap') {
        // make changes for small screen width
    } else {
        // `breakpointName` is 'default' as the new page width matches neither 'palm' nor 'lap'
    }
};

$.breakpoint.on(['palm', 'lap'], makeChanges);

$.breakpoint.off(callback)

To disable the calling of a callback when the breakpoint has changed, call $.breakpoint.off. The first and only parameter is the callback which should be disabled.

To disable the callback set above:

$.breakpoint.off(makeChanges);

$.breakpoint.changeBreakpoints(newDefaultBreakpoints)

In order to change the global breakpoints - which apply to all callbacks set using $.breakpoint.on, except those for which the breakpoints have been overridden - call $.breakpoint.changeBreakpoints.

The first and only parameter, newDefaultBreakpoints, is a map of the new breakpoints. The property names of this object correspond to the names used to refer to the breakpoints in calls to $.breakpoint.on. The format of each property of this map is an object with the properties min and max indicating the width of the window, in number of pixels, which should match this breakpoint. A breakpoint name of default is not advisable as this will lead to ambiguity when this is passed to a callback.

The default value for the breakpoints is:

{
    palm: {
        max: 719
    },
    lap: {
        max: 1023,
        min: 720
    },
    'lap-and-up': {
        min: 720
    },
    portable: {
        max: 1023
    },
    desk: {
        min: 1024
    }
}

breakpoint's People

Contributors

joshuabambrick avatar

Watchers

Arnstein Henriksen avatar James Cloos avatar  avatar

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.