All Projects → thecreation → breakpoints-js

thecreation / breakpoints-js

Licence: LGPL-3.0 License
Awesome Breakpoints in JavaScript. (bootstrap supported)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to breakpoints-js

mobx-react-matchmedia
A React HOC with mediaqueries for responsive layout
Stars: ✭ 32 (-54.29%)
Mutual labels:  responsive, breakpoints
breaking-point
BREAKING-POINT lets you quickly define and subscribe to screen (i.e. window) breakpoints in your re-frame application
Stars: ✭ 36 (-48.57%)
Mutual labels:  responsive, breakpoints
Anzeixer
Toolkit to Streamline View Definitions for Responsive Web Design
Stars: ✭ 62 (-11.43%)
Mutual labels:  responsive, breakpoints
octobercms-juicy-theme
Clean, simple and responsive landing page build on Vue.js with backend editing
Stars: ✭ 20 (-71.43%)
Mutual labels:  responsive
forest-templates
Source for https://semantic-ui-forest.com/templates/
Stars: ✭ 58 (-17.14%)
Mutual labels:  responsive
hope-ui-design-system
Hope UI - Open Source Bootstrap 5 Design System
Stars: ✭ 37 (-47.14%)
Mutual labels:  responsive
react-responsive-spritesheet
React component which helps you to easily apply responsive spritesheet animations on your project.
Stars: ✭ 82 (+17.14%)
Mutual labels:  responsive
bs-breakpoints
A plugin which detect Bootstrap 4 breakpoints and emit when there is a change
Stars: ✭ 22 (-68.57%)
Mutual labels:  breakpoints
gridsome-starter-liebling
Gridsome starter based on the Liebling theme for Ghost. Content is added via markdown, while Tailwind CSS is used for the layout/styling.
Stars: ✭ 21 (-70%)
Mutual labels:  responsive
40-lines-of-Sass
Full featured flexbox grid in 40 lines of Sass
Stars: ✭ 20 (-71.43%)
Mutual labels:  responsive
FlexBoxFX
FlexBoxFX is a JavaFX implementation of CSS3 flexbox.
Stars: ✭ 65 (-7.14%)
Mutual labels:  responsive
gatsby-netlifycms-starter-template
All the technologies used are free and open-source. You are free to use this template for a personal hobby blog, a commercial news agency or professional journalist website etc. Don't forget to star the repo if you like this template.
Stars: ✭ 33 (-52.86%)
Mutual labels:  responsive
motley
CSS Framework based on ITCSS
Stars: ✭ 24 (-65.71%)
Mutual labels:  responsive
advanced-responsive-video-embedder
Probably the the best WP plugin for embedding videos.
Stars: ✭ 32 (-54.29%)
Mutual labels:  responsive
nglp-angular-material-landing-page
NGLP is an Angular Material Landing Page.
Stars: ✭ 32 (-54.29%)
Mutual labels:  responsive
srcset.sh
A command line script that generates multiple responsive versions of an image at width breakpoints -- 320,480,640,768,960,1024,1280,1440 pixels wide -- that match common Mobile and widescreen desktop/laptop viewports using Imagemagick's convert utility and outputs the needed <img/> tag
Stars: ✭ 20 (-71.43%)
Mutual labels:  breakpoints
react-gallery-carousel
Mobile-friendly gallery carousel 🎠 with server side rendering, lazy loading, fullscreen, thumbnails, touch, mouse emulation, RTL, keyboard navigation and customisations.
Stars: ✭ 178 (+154.29%)
Mutual labels:  responsive
Sitegeist.Kaleidoscope
Responsive Images for Neos CMS
Stars: ✭ 27 (-61.43%)
Mutual labels:  responsive
use-breakpoint
React `useBreakpoint` hook to have different values for a variable based on a breakpoints.
Stars: ✭ 17 (-75.71%)
Mutual labels:  responsive
react-native-dimension
A React Native Dimension for Responsive Layout
Stars: ✭ 31 (-55.71%)
Mutual labels:  responsive

breakpoints-js bower NPM version Dependency Status prs-welcome

breakpoints-js is a lightweight, pure javascript library for attaching callbacks to breakpoints.

Table of contents

Main files

dist/
├── breakpoints.js
├── breakpoints.es.js
└── breakpoints.min.js

Quick start

Download the production version or the development version.

Install From Bower

bower install breakpoints.js --save

Install From Npm

npm install breakpoints-js --save

Install From Yarn

yarn add breakpoints-js

###Build From Source

If you want build from source:

git clone [email protected]:amazingSurge/breakpoints-js.git
cd breakpoints-js
npm install
npm install -g gulp-cli babel-cli
gulp build

Done!

Usage

Before you try anything, you need to include breakpoints.js in your page.

<script src="breakpoints.min.js"></script>

You may need provide a matchMedia polyfill if you wish to support old/incapable browsers.

Then you can init the script easily by code

<script type="text/javascript">
    Breakpoints();
</script>

Examples

There are some example usages that you can look at to get started. They can be found in the examples folder.

Defaults

It will use the bootstrap media query breakpoints by default:

Breakpoints.defaults = {
    // Extra small devices (phones)
    xs: {
        min: 0,
        max: 767
    },
    // Small devices (tablets)
    sm: {
        min: 768,
        max: 991
    },
    // Medium devices (desktops)
    md: {
        min: 992,
        max: 1199,
    },
    // Large devices (large desktops)
    lg: {
        min: 1200,
        max: Infinity
    }
};

You can set up your own breakpoints when initialize it:

<script type="text/javascript">
    Breakpoints({
        mobile: {
            min: 0,
            max: 767
        },
        tablet: {
            min: 768,
            max: 991
        },
        destop: {
            min: 992,
            max: Infinity
        }
    });
</script>

Methods

is

Check if the current screen is a specific size.

Breakpoints.is('xs'); // return true or false

get

Return the size object that you can operate it handily.

// get size object
var sm = Breakpoints.get('sm');

// attach events
sm.on('enter', function(){
    // do something
});

// remove event handler
sm.off('enter');

// get min width
sm.min // 768

// get max width
sm.max // 991

// get media query
sm.media // "(min-width: 768px) and (max-width: 991px)"

// check if it's current size
sm.isMatched(); // true or false

// you can do in a chain
Breakpoints.get('sm').on({
    enter: function(){

    },
    leave: function(){

    }
});

current

Return the current screen size object

Breakpoints.current();

on

Attach an event handler function for one or more events to the size

Breakpoints.on('md', {
    enter: function() {
        console.info('enter '+ this.name);
    },
    leave: function() {
        console.info('leave '+ this.name);
    }
});

Breakpoints.on('lg', 'enter', function(){
    console.info('hello lg');
});

Passing data to the callback

Breakpoints.on('sm', "enter", {
    name: "Addy"
}, function(data) {
    console.info(data.name + ' enter '+ this.name);
});

Breakpoints.on('sm', "leave", {
    name: "Karl"
}, function(data) {
    console.info(data.name + ' leave '+ this.name);
});

Unite sizes

Breakpoints.on('md lg', {
    enter: function() {
        console.info('enter '+ this.name);
    },
    leave: function() {
        console.info('leave '+ this.name);
    }
});

one

The handler attached to the size will executed at most once.

Breakpoints.one('md', 'enter', function(){
    console.info('this only appear once when enter md');
});

off

Remove event handlers attached to size.

// remove all events attached to sm size
Breakpoints.off('sm');

// remove all enter type events attached to md size
Breakpoints.off('md', 'enter'); 

// remove specific event handler
var enterHandler = function(){};
Breakpoints.on('lg', 'enter', enterHandler);

Breakpoints.off('lg', {
    enter: enterHandler
})

// alternative way
Breakpoints.off('lg', 'enter', enterHandler);

change

Attach an event handler to the size change event

// attach handler to change event
Breakpoints.on('change', function(){
    console.info('enter ' + this.current.name);
});

// altrnative example
var changeHandler = function(){
    // do something 
};
Breakpoints.on('change', changeHandler);

// remove the handler
Breakpoints.off('change', changeHandler);

// remove all change handlers
Breakpoints.off('change');

Browser support

Tested on all major browsers.

Safari Chrome Firefox Edge IE Opera
Latest ✓ Latest ✓ Latest ✓ Latest ✓ 9-11 ✓ Latest ✓
  • matchMedia browser support work perfect on all modern browsers (IE10+, firefox, chrome, android and safari).
  • With some polyfills (like the ones included in matchMedia.js) Breakpoints works perfect in IE6-9 as well.

Contributing

Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing. Make sure you're using the latest version of jquery-scrollTo before submitting an issue. There are several ways to help out:

Development

jquery-scrollTo is built modularly and uses Gulp as a build system to build its distributable files. To install the necessary dependencies for the build system, please run:

npm install -g gulp
npm install -g babel-cli
npm install

Then you can generate new distributable files from the sources, using:

gulp build

More gulp tasks can be found here.

Changelog

To see the list of recent changes, see Releases section.

Other Projects

If you like this project then I encourage you to check out a few of my other hand-selected projects.

  • enquire.js - A lightweight, pure JavaScript library for responding to CSS media queries.
  • mediaquery - A jQuery plugin for responsive media query events.
  • strapPoint - A small jQuery utility plugin to make working with Bootstrap breakpoints easier.
  • pointbreak.js - It provides a friendly interface to matchMedia with named media queries and easy to create callbacks.

Copyright and license

Copyright (C) 2016 amazingSurge.

Licensed under the LGPL license.

back to top

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].