Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

easy-designs/easy-resize-watchers.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easy Resize Watchers

This is a collection of scripts we routinely use to make building JavaScript interfaces that adapt to changes in screen size a breeze.

watchResize()

A global method for triggering callbacks when the browser is resized. The current viewport width (in pixels) is passed as an argument to callbacks.

Usage Example:

watchResize(function( size_in_px ){
  console.log( 'The browser is currently ' + size_in_px + 'px wide' );
});

getActiveMQ()

A global method for getting the current breakpoint name. Requires CSS similar to the following:

#getActiveMQ-watcher {
	font-family: "break-0";
	display: none;
}
@media only screen and (min-width: 20em) {
	#getActiveMQ-watcher {
		font-family: "break-1";
	}
}
@media only screen and (min-width: 30em) {
	#getActiveMQ-watcher {
		font-family: "break-2";
	}
}
@media only screen and (min-width: 48em) {
	#getActiveMQ-watcher {
		font-family: "break-3";
 	}
}

The value of the font-family declaration will be returned by the method. This is best used in concert with watchResize to get access to the value:

window.watchResize(function( size_in_px ){
	console.log( 'The browser is currently ' + size_in_px + 'px wide' );
	var breakpoint = getActiveMQ();
	console.log( 'The breakpoint is ' + breakpoint );
});

Releases

No releases published

Packages

No packages published