<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<section class="ravenous">
<h1>Please, resize your browser.</h1>
<p>Testing media queries with jQuery using
<strong>
<a href="http://caniuse.com/matchmedia" target="_blank">matchMedia</a>
</strong>
</p>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</section>
</body>
</html>
@import url(https://fonts.googleapis.com/css?family=Lobster|Ubuntu);
* {
box-sizing: border-box;
box-sizing: border-box;
box-sizing: border-box;
}
body {
width: 100%;
height: 100%;
background: crimson;
font-family: 'Lobster', cursive;
font-size: 18px;
font-weight: 400;
color: white;
overflow: hidden;
transition: background 1s ease-in;
transition: background 1s ease-in;
transition: background 1s ease-in;
transition: background 1s ease-in;
}
body a:active,
body a:link,
body a:visited {
color: inherit;
text-decoration: none;
}
body:before {
content: "The dashed line show the breakpoint";
font-family: 'Ubuntu', sans-serif;
text-align: center;
font-size: 12px;
padding: 0 20px;
text-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5);
text-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5);
display: inline-block;
position: absolute;
top: 5px;
left: 0;
right: 0;
margin: 0 auto;
}
body:after {
content: "";
width: 768px;
height: auto;
position: absolute;
top: -1px;
bottom: -1px;
left: 0;
right: 0;
margin: 0 auto;
border-left: 1px dashed rgba(250, 250, 250, 0.2);
border-right: 1px dashed rgba(250, 250, 250, 0.2);
outline: 1px dashed black;
}
.ravenous {
width: auto;
height: 100px;
position: absolute;
top: calc(50% - 50px);
left: 0;
right: 0;
text-align: center;
padding: 0 20px;
z-index: 1;
}
.ravenous h1 {
font-size: 45px;
line-height: 40px;
text-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5);
text-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5);
}
.ravenous p {
font-family: 'Ubuntu', sans-serif;
line-height: 22px;
margin-top: 10px;
text-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5);
text-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5);
}
.ravenous strong {
color: gold;
font-family: 'Lobster', cursive;
font-size: 22px;
border-bottom: 3px dotted;
transition: color 1s ease-in;
transition: color 1s ease-in;
transition: color 1s ease-in;
transition: color 1s ease-in;
}
// Testing media queries with jQuery
// Using matchMedia
// By Ravenous - July, 2014
(function($) {
/*
* We need to turn it into a function.
* To apply the changes both on document ready and when we resize the browser.
*/
function mediaSize() {
/* Set the matchMedia */
if (window.matchMedia('(min-width: 768px)').matches) {
/* Changes when we reach the min-width */
$('body').css('background', '#222');
$('strong').css('color', 'tomato');
} else {
/* Reset for CSS changes – Still need a better way to do this! */
$('body, strong').removeAttr('style');
}
};
/* Call the function */
mediaSize();
/* Attach the function to the resize event listener */
window.addEventListener('resize', mediaSize, false);
})(jQuery);
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |