Hosting Solutions
mobile_logo Table of Contents

Lights Out For Earth Day Tutorial Dark Page Switch

Learn to create a lights out for earth day script that uses light switch graphics and contrasting style sheets to allow the user to enter dark energy saving or dark theater mode. You can choose to use dark overlays that disable all page content, or you can use this approach which darkens the page exactly the way you want and all page elements remain fully active. <!DOCTYPE html> <html> <head> <link id="pagestyle" rel="stylesheet" type="text/css" href="default.css"> <style> img#lightSwitch { background:url(images/light_switch_down.jpg) no-repeat; cursor:pointer; } </style> <script> var mode = "default"; function swapStyleSheet(){ var pagestyle = document.getElementById('pagestyle'); var lightSwitch = document.getElementById('lightSwitch'); if(mode == "default"){ pagestyle.setAttribute('href', 'dark.css'); lightSwitch.src = "images/light_switch_down.jpg"; lightSwitch.title = "Turn the lights back on"; mode = "dark"; } else { pagestyle.setAttribute('href', 'default.css'); lightSwitch.src = "images/light_switch_up.jpg"; lightSwitch.title = "Turn the lights off"; mode = "default"; } } </script> </head> <body> <h1>CSS Javascript Lights Out Example</h1> <img id="lightSwitch" onmousedown="swapStyleSheet()" src="images/light_switch_up.jpg" width="19" height="46" alt="switch" title="Turn the lights off"> <h3 style="display:inline;">Pink Floyd - Shine On You Crazy Diamond</h3> <div id="special"> <iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe> </div> <h2>My web page has a lot off stuff on it</h2> </body> </html>

JavaScript Videos

General Programming

Flat Icons HTML Code Symbols Discovery JavaScriptHow to Program Code Syntax Highlighter Using JavaScriptFat Arrow Functions JavaScript Programming TutorialJavaScript Arguments Object Function TutorialJavaScript Storage Interface sessionStorage localStorage TutorialMulti Column Layout Grid Programming TutorialCustom Alert Box Programming TutorialCustom Confirm Box Programming TutorialCustom Prompt Box Programming TutorialChange CSS Class Style className Toggle TutorialPartial Print Document Tutorial HTML div ContentClick Outside Close Menu Box TutorialPercent Math Calculations Programming TutorialDual Image Reveal Control TutorialPage Loading Screen Document Preloader TutorialControl Panel Flyout Menu Windows AnimationsCustom Data Attributes HTML JavaScript CSS TutorialFullscreen API JavaScript Code Examples and SpecificationConsole Log Tutorial Chrome Firefox IE BrowsersToggle Function Click Drop Down Menus TutorialChange Tab Text and Window Title On The Fly TutorialDice Roll Programming Tutorial For Web Browser GamesDynamic Lorem Ipsum Placeholder Text TutorialBest HTML Event Handling addEventListener TutorialsetAttribute removeAttribute Methods TutorialDisabled User Handling Redirect WebsiteCapture Keyboard Input Tutorial HTML ApplicationCapture Keyboard Input Condition Logic TutorialChange Style Sheet Using Tutorial CSS Swap StylesheetWeb Page Overlay Tutorial Transparent CoverLights Out For Earth Day Tutorial Dark Page SwitchWindow Size Responsive CSS Layout Stylesheet Change TutorialRead Mouse Coordinates Pointer Position Tutorial