Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<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);
* {
  -webkit-box-sizing: border-box;
  -moz-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;
  -webkit-transition: background 1s ease-in;
  -moz-transition: background 1s ease-in;
  -o-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;
  -webkit-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;
  -webkit-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;
  -webkit-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;
  -webkit-transition: color 1s ease-in;
  -moz-transition: color 1s ease-in;
  -o-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

Dismiss x
public
Bin info
anonymouspro
0viewers