css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <main id="container" class="nightmode">
	<time id="date" class="clocktext"></time>
	<time id="time" class="clocktext"></time>
	<button id="gpsbutton">Get GPS Location</button>
	<div id="gps" class="clocktext infotext"></div>
</main>
  <!-- A simple clock that fits on an old iPhone 4s so you can reuse your old device as a wall clock. This version also includes geolocation. -->
            
          
!
            
              html {font-size:16px;}
body {
    padding:0;
    margin:0;
    font-family:TrebuchetMS,Arial,sans-serif;
}
#container {
    margin:0 auto;
    padding:0;
    width:100vw;
    height:100vh;
    text-align:center;
    overflow:hidden;
}
.nightmode {
    background-color:#121212;
    background-image: linear-gradient(to bottom left, #121212 10%,#333955 100%);
    color:#fff;
    text-shadow:1px 1px 1px black;
}
.daymode {
    background-color: #87ceeb;
    background-image: linear-gradient(to bottom left, #87ceeb 0%,#fff 100%);
    color:#333;
    text-shadow:1px 1px 10px white;
}
.clocktext {
    display:block;
    margin:0;
    padding:1px 0 0 0;
    width:100%;
    text-align:center;
    line-height:1.2;
    white-space:nowrap;
}
.infotext {
    padding:0 5px 0 5px;
    font-size:1.3rem;
    line-height:1.4;
    width:auto;
}
#date {
    font-size:1.3rem;
    padding-top:15px;
}
#time {
    font-size:5rem;
    margin:1px 0 0 0;
}
#time span {
    display:inline-block;
    padding:0;
    vertical-align: baseline;
    text-align:left;
    width: 2em;
    margin:0 0 0 0.5em;
    font-size:1.5rem;
    line-height:1.5;
    white-space:normal;
}
#gpsbutton {
    -webkit-appearance: none;
    -moz-appearance: none;
    display:block;
    margin:0 auto;
    padding:0 16px 0 16px;
    width:auto;
    height:40px;
    border:2px outset #fff;
    border-radius:12px;
    background:#dedeff;
    color:black;
    font-size:20px;
    cursor:pointer;
}
#gpsbutton:hover {
    background:#000033;
    border:2px inset #fff;
    color:#fff;
}
@media (min-width: 480px){
    #date {font-size:2rem;}
    #time {font-size:8rem;}
    #time span {
        font-size:2rem;
        line-height: 2;
    }
   .infotext {
        font-size:1.8rem;
    }
}


            
          
!
            
              //NOTE: ES5 chosen instead of ES6 for compatibility with older mobile devices
var now, dd, td;
var lat, lon, gd, gpsbutton;
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

document.addEventListener("DOMContentLoaded", init, false);
function init(){
  dd = document.getElementById("date");
  td = document.getElementById("time");
  gd = document.getElementById("gps");
  gpsbutton = document.getElementById("gpsbutton");
  gpsbutton.addEventListener("click",getLocation,false);
  updateTime();
  setInterval(updateTime,1000);
}
function updateTime(){
  var clockdata = getClockStrings();
  dd.innerHTML = clockdata.datehtml;
  td.innerHTML = clockdata.timehtml;
  dd.dateTime = now.toISOString();
  td.dateTime = now.toISOString();
  var sec = now.getSeconds();
  var minutes = now.getMinutes();
  if (sec === 0){
    if (minutes % 5 === 0){
      getLocation(); //get location every 5 minutes while the app is running
    }
  }
}
function getClockStrings(){
  now = new Date();
  var year = now.getFullYear();
  var month = months[now.getMonth()];
  var date = now.getDate();
  var day = days[now.getDay()];
  var hour = now.getHours();
  var minutes = now.getMinutes();
  var seconds = now.getSeconds();
  var meridian = hour < 12 ? "AM" : "PM";
  var clockhour = hour > 12 ? hour - 12 : hour;
  if (hour === 0) {clockhour = 12;}
  var clockminutes = minutes < 10 ? "0" + minutes : minutes;
  var clockseconds = seconds < 10 ? "0" + seconds : seconds;
  var datehtml = day + ", " + month + " " + date + ", " + year;
  var timehtml = clockhour + ":" + clockminutes + "<span>:" + clockseconds + " " + meridian + "</span>";
  return {"datehtml":datehtml,"timehtml":timehtml};
}

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  }else{
    gd.innerHTML = "location unknown";
    firsttime = false;
  }
}
function showPosition(position) {
  gpsbutton.style.display = "none";
  lat = position.coords.latitude;
  lon = position.coords.longitude;
  gd.innerHTML = "GPS: " + lat.toFixed(2) + "&nbsp;|&nbsp;" + lon.toFixed(2);
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console