• Stars
    star
    240
  • Rank 168,229 (Top 4 %)
  • Language
    JavaScript
  • Created over 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Control JS with mediaqueries
                      _ _        ____ _               _
   _ __ ___   ___  __| (_) __ _ / ___| |__   ___  ___| | __
  | '_ ` _ \ / _ \/ _` | |/ _` | |   | '_ \ / _ \/ __| |/ /
  | | | | | |  __/ (_| | | (_| | |___| | | |  __/ (__|   <
  |_| |_| |_|\___|\__,_|_|\__,_|\____|_| |_|\___|\___|_|\_\

This is a simple wrapper around matchMedia to run code on entry and exit from media queries. It also uses browser resize as a fallback for browsers that don't support matchMedia.

Demo

There are two examples here: http://sparkbox.github.io/mediaCheck/

media

Type: string

This is the mediaquery that will trigger the specified action. It should be in the form:

  • (min-width: 420px)
  • (min-width: 35em)
  • (max-width: 800px)
  • (max-width: 60em)

entry

Type: function

This function will execute once when the mediaquery becomes active.

exit

Type: function

This function will execute once when the mediaquery becomes inactive.

both

Type: function

This function will execute once when the mediaquery changes state.

Usage Example:

mediaCheck({
  media: '(max-width: 420px)',
  entry: function() {
    console.log('starting 420');
  },
  exit: function() {
    console.log('leaving 420');
  },
  both: function() {
    console.log('changing state');
  }
});

Change History

  • 1.0.3
    • Fixes a bug that caused the both function to
      only work on exit, but not entry.
  • 1.0.0
    • Drop support for IE < 10
  • 0.4.6
    • You can now pass combined mediaqueries e.g. (min-width: 320px) and (max-width: 800px)
    • It also now accepts [min|max]-aspect-ratio
  • 0.4.5
    • Passing mq to entry, exit, and both

License

Creative Commons Attribution-ShareAlike 3.0 Unported License https://creativecommons.org/licenses/by-sa/3.0/

More Repositories

1

bouncy-ball

🔴 Compare web animation techniques by bouncing a ball with each one.
JavaScript
605
star
2

style-prototype

Example of an HTML/CSS style tile.
CSS
354
star
3

standard

How we work and best practices
Shell
291
star
4

email-lab

📩 Starter project for designing and testing HTML email templates
JavaScript
283
star
5

Build-Responsively-Workshop

CSS
243
star
6

apprenticeships

📖 A guide to the Sparkbox apprenticeships.
223
star
7

mediaQueryBookmarklet

Determine current page dimensions and current media query
JavaScript
159
star
8

Custom-Selectbox

Select box UI replacement
JavaScript
70
star
9

Responsive-Retrofitting

Playing around with a few ideas...
JavaScript
57
star
10

project-init

Our starting point of front-end development
JavaScript
46
star
11

commit-colors

🎨 See a lovely color swatch in your terminal every time you author a commit.
Go
41
star
12

br-frontend-tooling-links

Links and resources for our Build Right: Frontend Tooling workshop
36
star
13

SB-Media

Repo for our Media Query mixin.
Ruby
32
star
14

mashboard

Mashing the Code Mash website into something more usable
CoffeeScript
31
star
15

generator-mg

Mg is the Yeoman scaffold for all Sparkbox frontend projects.
JavaScript
27
star
16

logo-experiments

Every possible way to draw the Sparkbox logo, using modern frontend techniques.
HTML
22
star
17

design-system-starter

Use this project as a starting point for new design systems
SCSS
19
star
18

br-frontend-tooling-demo

The demo project for the Frontend Tooling workshop
CSS
19
star
19

gulp-starter

A starter kit for static templates based on Gulp.
JavaScript
12
star
20

mina-circle

🚀 A deployment wrapper for mina based, artifact deployment.
Ruby
9
star
21

cachebust

A simple node cachebust tool
JavaScript
8
star
22

sparkle

A highly customizable utility-based CSS Framework
SCSS
8
star
23

designsystemssurvey

The Design Systems Survey - Sparkbox
SCSS
8
star
24

safe-focus

Safe Focus is a utility file that adds custom outline styles for all selectable components.
JavaScript
7
star
25

site-ignite

An Electron app that aims to be a GUI wrapper around our static template projects.
CSS
7
star
26

lamppost

💡 Sparkbox's 2016 apprentice project: an aggregate of local tech events.
HTML
7
star
27

CodeMash-RWD

Example files for "Hands-On Responsive Web Design"
6
star
28

br-modern-javascript-exercises

JavaScript
5
star
29

react-eq

Element Queries for React
JavaScript
5
star
30

aws-infrastructure

HCL
5
star
31

sparkeats

Food reviews and restaurant ratings
TypeScript
4
star
32

sparkpress-wordpress-starter

WordPress Starter within a Docker Container
JavaScript
4
star
33

trivia11y

Questions and answers for either studying or fun (or both).
SCSS
4
star
34

exploring-cohort

JavaScript
4
star
35

dr-style-prototype

Dress Responsively style prototype for use at Build Responsively
JavaScript
4
star
36

sb

A CLI to generate SSH Certificates after verifying your identity via Slack.
Go
4
star
37

sparkbox-wraith

Receive notifications when potential visual bugs are introduced in your code.
JavaScript
4
star
38

carbon

🌑 Carbon: Core elements for Sparkbox projects
JavaScript
4
star
39

MochaJasmineTests

JavaScript
3
star
40

accessible-components

A set of useful guides to building accessible components.
JavaScript
3
star
41

vue-storybook-starter

A Starter Vue Storybook Project
JavaScript
3
star
42

lunch-bot

A Slack bot to remind us of our lunch duties.
JavaScript
3
star
43

tech-events-dayton

A list of tech-related events in the Dayton, Ohio area.
HTML
3
star
44

apprentice-at

An online listing of apprenticeship opportunities.
Handlebars
3
star
45

Responsive-Slider

JavaScript
3
star
46

br-modern-css-demo

A demo for the Build Right Modern CSS Workshop
CSS
3
star
47

apprentices-page

A page that shows past and current apprentices at Sparkbox
HTML
3
star
48

br-frontend-testing-exercises

Demos and examples for the super, spectacular Build Right: Frontend Testing workshop by @sparkbox
JavaScript
3
star
49

dashing-js-redis

Redis based history store for dashing-js
JavaScript
2
star
50

project-bot

JavaScript
2
star
51

splinter

🐭 Parse and split SCSS files based on functions and mixins.
JavaScript
2
star
52

make-fluid

testing out an idea
JavaScript
2
star
53

apprenticeship-sparkhero

Pow! Bam! The SparkHero App, along with its trusty sidekick the SparkHero API, is the perfect repository to get your feet wet building web applications.
JavaScript
2
star
54

srcN

srcN polyfill
JavaScript
2
star
55

commit-haikus

A bot that tweets out accidental commit message haikus.
JavaScript
2
star
56

code-styleguides

2
star
57

stuntman

JavaScript
1
star
58

full-stack-beginners-guide

A Beginner's Guide to Learning Full Stack Web Development
HTML
1
star
59

select-testing

A repo to test how Dropdown jQuery plugins (Chosen, Select2, possibly more) react under fluid and fixed width environments
JavaScript
1
star
60

ExpressionEngine-Plug-ins

PHP
1
star
61

EE2-Gist-Plugin

PHP
1
star
62

1000kperminute

JavaScript
1
star
63

cz-sparkbox

Sparkbox Commitizen template
JavaScript
1
star
64

apprentice-application

A Rails project by the current apprentices.
Ruby
1
star
65

cincicopter-13

Code for Sparkbox AR Drone at CinciCopter on 2013-09-07
JavaScript
1
star
66

carbon-cli

TypeScript
1
star
67

ember-cli-grunticon

"A mystical CSS icon solution" for ember.
JavaScript
1
star
68

mina-cloudflare-purge

Remove files from a Cloudflare zone cache
Ruby
1
star
69

Grunt-Demo

Grunt Basics
JavaScript
1
star
70

downpour

SCSS
1
star
71

fed-final-project

JavaScript
1
star
72

advanced-techniques-in-git

A small repo to practice advanced Git techniques.
1
star
73

testing-code-challenge

JavaScript
1
star
74

sparkbot

Sparkbox's Hubot for Slack.
CoffeeScript
1
star
75

eslint-config-sparkbox

✅ A set of eslint customizations that we use at Sparkbox.
JavaScript
1
star