Code Monkey home page Code Monkey logo

responsive-bootstrap-toolkit's Introduction

Responsive Bootstrap Toolkit

Responsive Bootstrap Toolkit provides an easy way of breakpoint detection in JavaScript, detecting changes in currently active breakpoint, as well as executing any breakpoint-specific JavaScript code. Despite the name, you can use it also with Foundation, or any other framework.

Current version: 2.5.0

Documentation

HOW-TO

Installation

bower install responsive-toolkit

Demo

Live example available on CodePen. Hosted along with repository are the following usage examples:

Basic usage:

// Wrap IIFE around your code
(function($, viewport){

    // Executes only in XS breakpoint
    if( viewport.is('xs') ) {
        // ...
    }

    // Executes in SM, MD and LG breakpoints
    if( viewport.is('>=sm') ) {
        // ...
    }

    // Executes in XS and SM breakpoints
    if( viewport.is('<md') ) {
        // ...
    }

    // Execute code each time window size changes
    $(window).resize(
        viewport.changed(function(){
            if( viewport.is('xs') ) {
                // ...
            }
        })
    );

})(jQuery, ResponsiveBootstrapToolkit);

Execute code on window resize

Allows using custom debounce interval. The default one is set at 300ms.

$(window).resize(
    viewport.changed(function(){

      // ...

    }, 150)
);

Get alias of current breakpoint

$(window).resize(
    viewport.changed(function(){
        console.log( 'Current breakpoint: '+ viewport.current() );
    })
);

Using with Foundation

Instead of Bootstrap's aliases xs, sm, md and lg, Foundation uses: small, medium, large, and xlarge.

(function($, viewport){

    viewport.use('Foundation');

    if( viewport.is('small') ) {
        // ...
    }

})(jQuery, ResponsiveBootstrapToolkit);

Note: Currently, only Foundation 5 visibility classes are supported. If you'd like to support older version of any framework, or provide your own visibility classes, refer to example below.

Providing your own visibility classes

(function($, viewport){

    var visibilityDivs = {
        'alias-1': $('<div class="device-alias-1 your-visibility-class-1"></div>'),
        'alias-2': $('<div class="device-alias-2 your-visibility-class-2"></div>'),
        'alias-3': $('<div class="device-alias-3 your-visibility-class-3"></div>')
    };

    viewport.use('Custom', visibilityDivs);

    if( viewport.is('alias-1') ) {
        // ...
    }

})(jQuery, ResponsiveBootstrapToolkit);

Note: It's up to you to create media queries that will toggle div's visibility across different screen resolutions. How? Refer to this example.

How do I include it in my project?

Paste just before </body>

<!-- Responsive Bootstrap Toolkit -->
<script src="js/bootstrap-toolkit.min.js"></script>
<!-- Your scripts using Responsive Bootstrap Toolkit -->
<script src="js/main.js"></script>

Migrating from an older version

Refer to the changelog for a list of changes in each version of the library.

Dependencies:

  • jQuery
  • Bootstrap's responsive utility css classes (included in its standard stylesheet package)

responsive-bootstrap-toolkit's People

Contributors

maciej-gurban avatar nikita240 avatar 5ervant avatar

Watchers

 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.