Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div class="container">
    I'm dynamic content that is depending on media. Resize the window...
  </div>
  
</body>
</html>
 
html {
  box-sizing: border-box;
  font-family: Helvetica, Arial, sans-serif;
  color: rgba(0, 0, 0, 0.7);
}
*, *:before, *:after {
  box-sizing: inherit;
}
.container {
  margin: 1rem 0;
  padding: 2rem;
  background: yellow;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
}
 
(function(w, d){
  var dynamicContent = {
    'screen and (max-width: 240px)': 'This is a very tiny viewport!',
    'screen and (min-width: 241px) and (max-width: 640px)': 'Not tiny but still very small viewport!',
    'screen and (min-width: 641px)': 'Medium sized viewport'
  };
  
  w.addEventListener('load', function() {
  
    Object.keys(dynamicContent).forEach(function(mediaQuery) {
      var mql = w.matchMedia(mediaQuery);
      mql.addListener(function() {
        if(mql.matches) {
          d.querySelector('.container').innerHTML = dynamicContent[mediaQuery];
        }
      });
    });
  
  });
  
}(window, document));
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
gionkunzpro
0viewers