octocatstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource
via CSS Lint

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource
via JS Hint

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Want a Run Button?

If active, the preview will update automatically when you change code.

HTML

            
              <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width"/>
<link href='http://fonts.googleapis.com/css?family=Give+You+Glory' rel='stylesheet' type='text/css'> 
</head>

<body>
<h2>Responsive UI with Ambient Light Events</h2>
<h1>Demo</h1>
<p>Sensor value:<br>
<span id="result">AmbientLightEvent is not supported</span></p>
    
<p>Sensor value in string:<br>
<span id="resultLevel">LightLevelEvent is not supported</span></p>

<p>
  <img src="http://placekitten.com/300/160"/>
</p>
  
  <p>I finally wrote up an article about this demo: <a href="http://girliemac.com/blog/2014/01/12/luminosity/">girliemac.com/blog/2014/01/12/luminosity/</a>
  </p>
<p>
  Kitty ipsum dolor sit amet, lay down in your way lay down in your way lick puking run, eat jump climb the curtains toss the mousie I don’t like that food eat. Zzz catnip sleep in the sink lay down in your way, claw zzz lay down in your way attack meow catnip. Knock over the lamp climb the curtains attack your ankles eat the grass, sniff climb the curtains fluffy fur judging you attack chuf chase the red dot.
</p>
<p>Kitty ipsum dolor sit amet, lay down in your way lay down in your way lick puking run, eat jump climb the curtains toss the mousie I don’t like that food eat. Zzz catnip sleep in the sink lay down in your way, claw zzz lay down in your way attack meow catnip. Knock over the lamp climb the curtains attack your ankles eat the grass, sniff climb the curtains fluffy fur judging you attack chuf chase the red dot.
</p>
  
  <p>
    Tail flick stuck in a tree lick sunbathe scratched attack your ankles, lick litter box litter box puking hiss. Attack zzz toss the mousie run climb the curtains, sleep on your keyboard litter box chase the red dot sleep in the sink lick zzz claw. Stuck in a tree kittens sleep on your keyboard lick run, knock over the lamp hiss zzz sleep on your keyboard feed me meow jump. Stretching catnip stuck in a tree scratched, run stuck in a tree stuck in a tree lick feed me sleep in the sink tail flick bat. Rip the couch scratched eat hiss, I don't like that food eat claw lay down in your way bat scratched climb the curtains biting. Puking stuck in a tree meow attack judging you, sleep in the sink give me fish stretching rip the couch purr fluffy fur.
  </p>
</body>
</html>
            
          
!

CSS

            
              * {
	box-sizing: border-box;
}
html, input {
    font-family: "Segoe UI Web Light", "Segoe UI Light", "Segoe UI Web Regular", "Segoe UI", "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 
}
html {
    -ms-text-size-adjust: none;
}
html, body {
	padding: 0;
	margin: 1em;
	height: 100%;
}
body,
body.normal {
  /* default in mormal luminosity level */
  background-color: #d7d7d7;
  color: #111;
}
body.dim {
  background-color: #444;
  color: #fff;
}
body.bright {
  background-color: #fff;
  color: #333;
}
a {
	color: green;
}
header {
	margin-bottom: 1em;
}
h1, h2, h3 {
	margin: 0;
	font-weight: normal;
}
h1 {
	font-size: 3.375rem;
	text-transform: lowercase;
}
h2 {
	font-size: 1rem;
	text-transform: uppercase;
}

#result, #resultLevel {
  color: red;
}


            
          
!

JS

            
              window.addEventListener('devicelight', function(e) {
  var lux = e.value;
  document.querySelector('#result').textContent = lux + ' lux';
  
  if(lux < 50) {
    document.body.className = 'dim';
  }
  if(lux >= 50 && lux <= 1000) {
    document.body.className = 'normal';
  }
  if(lux > 1000)  {
    document.body.className = 'bright';
  }
  
});

window.addEventListener('lightlevel', function(e) {
  var level = e.value; document.querySelector('#resultLevel').textContent = level;
  
  if(level === 'dim') {
    document.body.className = 'dim';
  }
  if(level === 'normal')  {
    document.body.className = 'normal';
  }
  if(level === 'bright')  {
    document.body.className = 'bright';
  }
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console