Git Product home page Git Product logo

screenstate-js's Introduction

##screenstate.js

This is a tiny responsive breakpoint tool. It is intended to be used as a simple Javascript compliment to the @media screen and (max-width: xxx) in CSS. Logic can be executed between screen breakpoint changes through either callbacks or event listeners. The tool also includes a toggleable debug indicator.

Example

###Include necessary files

<script type="text/javascript" src="screenstate.js"></script>
<link rel="stylesheet" type="text/css" href="screenstate.css"/>

Optional: jQuery (for events)

<script type="text/javascript" src="jquery-1.10.2.min.js"></script>

###Initialize Screenstate Manager and add ScreenStates

Ranges of screen resolutions are represented with the ScreenState object. For example, screens between 480px to 800px are represented by a ScreenState object with minWidth of 480 and maxWidth of 800. The ScreenState constructor takes a parameter array with the folowing options: minWidth
maxWidth
name
debugColor (optional, a color will be automatically chosen if not set)

var sSM = new ScreenStateManager(true);		
var desktop = screenStateManager.add(new ScreenState(
	{
		minWidth: 768, 
		maxWidth: 65536, 
		name: 'Desktop'
	}
));		
var mobile = screenStateManager.add(new ScreenState(
	{
		minWidth: 0, 
		maxWidth: 767, 
		name: 'Mobile'
	}
));

###Respond to breakpoint changes

You can respond to screenState changes by either adding a callback function to a ScreenState:

desktop.addEnterCallback(function() { 
	console.log("Entered: Desktop Screen"); 
});

desktop.addExitCallback(function() { 
	console.log("Exited: Desktop Screen"); 
});

Or by listening for "screenstate_enter" or "screenstate_exit" events on window:

jQuery(window).on("screenstate_enter", function(e, screenState) {
... your logic goes here ..
});

##Projects using screenstate.js www.williamashley.com

screenstate-js's People

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.