Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>World clocks</h1>
<input type="text" id="searchCity" value="" placeholder="City" disabled><div id="clear">✕</div>
<div id="listCitysFound"></div>
<input id="buttonOk" type="button" value="Add clock" disabled>
<input id="buttonSort" type="button" value="Sort" disabled>
<div id="fullscreenZone">
    <div id="container"><div class="clock" id="model">            
        <div class="base">
            <div class="hour"><div><div></div></div></div>
            <div class="minute"><div><div></div></div></div>
            <div class="second"><div><div></div></div></div>
            <div class="day"></div>
            <div class="title"></div>            
            <div class="deleteClock">✕</div>
            <div class="utc"></div>
            <div class="zone"></div>
            <div class="apm"></div>
        </div>        
    </div></div>
     <div id="fullscreen" class="fullscreen"></div>
</div>
<a href="http://www.wdisseny.com/time-in-the-city/" target="_parent">Get the time of any city. API</a>
              
            
!

CSS

              
                html,body{
margin: 0;
height: 100%;
background-color: lightgray; 
}
body{
font-size: 16px;
font-family: sans-serif;

overflow-y: scroll;

}
#searchCity,#listCitysFound{
box-sizing: border-box;
width: 300px;
max-width: 100%;
}
#clear{
display:inline-block;
position:absolute;
font-size: 24px;
line-height:35px;
margin-left:-30px;
cursor:pointer;
}
#searchCity{
border:none;
font-size: 24px;
line-height:35px;
box-sizing: border-box;
padding: 0;
padding-left: 5px;
outline: none;
}
#buttonOk,#buttonSort{
font-size: 24px;
padding: 0 10px;
line-height:35px;
box-sizing: border-box;
margin-left:5px;
border:none;
background-color: RoyalBlue;
color:white;
cursor:pointer;
transition:.2s;
box-sizing: border-box;
}
#buttonOk:disabled,#buttonSort:disabled{
background-color:darkgray;
cursor:default;
border:none;
color:lightgray;
transform:scale(.9);
}
#searchCity,#listCitysFound{
margin-left:10px;
}
#listCitysFound{
position:absolute;
border:1px solid white;
background-color: white;
box-shadow: 5px 5px 5px gray;
font-size: 18px;
margin-top: 1px;
z-index:2;
}
#listCitysFound>div{
padding: 3px 5px;
cursor: pointer;
}
#listCitysFound>div>b{
color:RoyalBlue;
}
#listCitysFound>div:hover{
background-color: lightgray;
}
#listCitysFound small{
color:gray;
font-size: 13px;
}
#listCitysFound:empty{
border: none;
}
#container{
display:table;
margin:auto;    
background-image: url("data:image/svg+xml;utf8, <svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'  viewBox='0 0 100 100' width='100px' height='100px'><path d=' M 10,10 l80,0 l0,80 l-80, 0 z'  stroke-width='0' stroke='rgb(0,0,0)' fill='rgba(0,0,0,.1)'/></svg>");
 
}

.clock,.clockSpace{
--canon:250px;
width: var(--canon);
height:  var(--canon);
position:relative;
display: inline-block;
vertical-align: top;
margin:  calc( var(--canon) / 12 );
overflow: hidden;
transition:.2s ease-in;
white-space: nowrap;
z-index: 0;
background-color: lightgray;
}
.clockSpace{
background-color:transparent;    
}
.clock .base{
border:1px solid gray;
border-color: white gray gray white;
box-sizing: border-box;
height:  var(--canon);
display:flex;
justify-content: center;
font-size: calc( var(--canon) /  8 );
color:rgba(0, 0, 0,.7);
font-family: serif;
background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255,.3) 20%,transparent , rgba(0, 0, 30,.2) 80%);
}
.clock>.base>div{
position:absolute; 
}
.hour,.minute,.second{
filter:drop-shadow( calc( var(--canon) / 70 ) calc( var(--canon) / 70 ) calc( var(--canon) / 70 ) rgba(0, 0, 0, .4));
height: 100%;
width: 100%;
}
.hour{
z-index: 1;
} 
.hour>div {
height: 100%;
transition: 2s ease; 
overflow: hidden;
}
.hour>div>div{
background-color: rgb(20, 20, 20);     
width: 2.5%;
height: 35%;
margin: auto;
margin-top:20%;
}
.minute{
z-index: 2;
}
.minute>div {
height: 100%;
transition: 2s ease;  
overflow: hidden;
}
.minute>div>div{
background-color:rgb(20, 20, 20); 
width: 2.5%;
height: 45%;
margin: auto;
margin-top:10%;
}
.second{
z-index: 3;
visibility:hidden;
}
.clock:first-child .second{
visibility: visible;
}
.second>div {
height: 100%;
transition:transform 2s ease;  
overflow: hidden; 
}
.second>div>div{
width: 1%;
height: 48%;
margin: auto;
margin-top:7%;
background-color: rgb(200, 0, 0);
}
.title{
margin-top:calc(var(--canon) / 1.8);
font-family:arial, sans-serif;
font-size: calc( var(--canon) /  10 );
transition: .4s ease .4s;
}
.day{
top:calc(50% -  (var(--canon) /  20));
left:65%;
font-family:arial;
font-size: calc( var(--canon) /  12 );
line-height: calc( var(--canon) /  10 );
width: calc( var(--canon) /  9 );
text-align: center;
background-color:darkgray;
color:white;
}   
.deleteClock{
top:0;
right: calc(var(--canon) / 20);
cursor:pointer;
height: auto !important;
color:black;
z-index: 3;
}
@media (hover: hover) {
    .deleteClock{
    visibility:hidden;
    opacity:0;
    transition: .4s ease .3s;
    transform:scale(0);

    }
    .clock:hover .deleteClock{
    visibility:visible;
    opacity:1;
    transform:scale(1);
    color: rgb(100, 0, 0);


    }
    .clock:hover .title{
    color:rgb(100,0,0);
    }
    #fullscreen:hover{
    transform:scale(1.1)
    }
}
.utc,.zone,.apm{
font-size: calc(var(--canon) / 18);
font-family: arial;
}
.utc{
left: 2%;
bottom: 1%;
color: black;
}
.zone{
top:1%;
left: 2%;
}
.apm{
right: 2%;
bottom: 1%;
font-weight: bold;
}
@keyframes clock {
    0% {transform: rotate(0deg)}
    100% {transform:rotate(360deg)}
}
a{
color:black;
display:table;
margin-bottom: 100px
}
h1{
margin:0;
font-weight: normal;
font-size: 24px;
}
#fullscreen{
height: 32px;
width: 32px;
position:absolute;
top:10px;
right: 10px;
cursor: pointer;
transition:.24s;
z-index: 1000;
}

.fullscreen{
background-image: url("data:image/svg+xml;utf8, <svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><path d=' M 2 2 L 14 2 L 14 6 L 6 6 L 6 14 L 2 14 L 2 2 Z  M 2 30 L 14 30 L 14 26 L 6 26 L 6 18 L 2 18 L 2 30 Z  M 30 2 L 18 2 L 18 6 L 26 6 L 26 14 L 30 14 L 30 2 Z  M 30 30 L 18 30 L 18 26 L 26 26 L 26 18 L 30 18 L 30 30 Z ' fill='black'/></svg>");
  
}
.fullscreenOff{
background-image: url("data:image/svg+xml;utf8, <svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><path d=' M 14 14 L 2 14 L 2 10 L 10 10 L 10 2 L 14 2 L 14 14 Z  M 14 18 L 2 18 L 2 22 L 10 22 L 10 30 L 14 30 L 14 18 Z  M 18 14 L 30 14 L 30 10 L 22 10 L 22 2 L 18 2 L 18 14 Z  M 18 18 L 30 18 L 30 22 L 22 22 L 22 30 L 18 30 L 18 18 Z ' fill='black'/></svg>");
  
}
@media screen and (display-mode: fullscreen) {
    #fullscreenZone {
    background-color: lightgray;
    overflow-y: auto;
    height: 100%;
    display:flex;
    }
    .clockSpace{
    display:none;
    }
}
#fullscreenZone{
background-color: lightgray; 
}
              
            
!

JS

              
                var base = document.querySelector(".base")
var angle = 0
for (i = 0; i < 12 ; i++){
    mark = document.createElement("div")
    mark.innerHTML = i + 1
    angle += 30
    mark.style.height = "100%"
    mark.style.transform="rotate("+angle+"deg)"
    base.appendChild(mark)
}
var container = document.getElementById("container")
var clockModel = document.getElementById("model")
var HTMLclock = clockModel.innerHTML
var clockAreaWidth = container.offsetWidth
container.style.backgroundSize = clockAreaWidth + "px"
clockModel.className = "clockSpace"
clockModel.innerHTML = ""
    
function whidthContainer(){
    container.style.width = parseInt(document.body.offsetWidth / clockAreaWidth) * clockAreaWidth + "px"
}
    
whidthContainer()
window.onresize = whidthContainer
   
function set(clockHand, deg, timeAnimation) {
    clockHand.style.animation = ""
    setTimeout(function(){
        var rotation = 'rotate(' + deg + 'deg)'
        clockHand.style.animation ="clock linear " + timeAnimation + "s infinite"
        clockHand.querySelector("DIV").style.transform = rotation
    },20)
}
    
function apmDayChange(objectCity,timeCity){
    var hour = timeCity.getHours()    
    var HTMLday = objectCity.querySelector( ".day")
    HTMLday.innerHTML = timeCity.getDate()
    var HTMLapm = objectCity.querySelector( ".apm")
    HTMLapm.innerHTML = (hour<12) ? "AM" : "PM"
    var nextHour = new Date(timeCity)
    nextHour.setMilliseconds(100)
    nextHour.setSeconds(0)
    nextHour.setMinutes(0)
    nextHour.setHours(hour+1)
    objectCity.timeout = setTimeout(function(){
        HTMLapm.innerHTML = (nextHour.getHours()<12) ? "AM" : "PM"
        HTMLday.innerHTML = nextHour.getDate()
        objectCity.timeout =setInterval(function(){
            nextHour.setHours(nextHour.getHours()+1)
            HTMLday.innerHTML = nextHour.getDate()
            HTMLapm.innerHTML = (nextHour.getHours()<12) ? "AM" : "PM"
        }, 60 * 60 *1000)
    },nextHour-timeCity)
    
}
    
function startClock(objectCity){
    var timeCity = new Date(
        (new Date).getTime() + // local time
        (new Date).getTimezoneOffset() * 60 * 1000  + // UTC time
        city[objectCity.id].timezoneOffset * 1000 // Offset UTC time
    )
    set(objectCity.querySelector(".hour"), 30 * (timeCity.getHours() + timeCity.getMinutes() / 60), 60 * 60 * 24)
    set(objectCity.querySelector(".minute"), 6 * (timeCity.getMinutes() + timeCity.getSeconds() / 60), 60 * 60)
    set(objectCity.querySelector(".second"), 6 * (timeCity.getSeconds() + timeCity.getMilliseconds() / 1000), 60)
    apmDayChange(objectCity,timeCity)    
}
buttonSort = document.getElementById('buttonSort') 
buttonSort.disabled = true   
buttonSort.onclick = function(){    
    var order = []
    document.querySelectorAll('.clock').forEach(function(clock){
        order.push({id:clock.id,timezoneOffset:clock.timezoneOffset})
    })
    order.sort(function(a,b){return Number(b.timezoneOffset) - Number(a.timezoneOffset) })
    selectedCities = []
    container.innerHTML='<div class="clockSpace" id="model"><\/div>'
    buttonSort.disabled = true
    order.forEach(function(clock){        
        createHTMLclock(clock.id)
    })
}
function  activateOrderButton(){
    var clock = document.querySelectorAll('.clock')   
    buttonSort.disabled = true
    for (var i=0;i<clock.length-1;i++){
        if (Number(clock[i].timezoneOffset)>Number(clock[i+1].timezoneOffset)) buttonSort.disabled = false
    }
}  
function createHTMLclock(cityName){
    var div = document.createElement("DIV")
    div.className= "clock"
    div.id=cityName
    div.innerHTML = HTMLclock
    div.querySelector( ".title").innerHTML = cityName.replace(/_/g, " ");
    div.querySelector( ".utc").innerHTML = city[cityName].timezoneUTC;
    div.querySelector( ".zone").innerHTML = city[cityName].zone.replace(/\/|_/g, "<br>");
    div.timezoneOffset = city[cityName].timezoneOffset
    div.style.transform = "scale(0)"
    div.style.width = 0
    container.insertBefore(div,container.firstChild)
    var deleteClock = div.querySelector( ".deleteClock")
    deleteClock.clock = div
    deleteClock.onclick = function(){
        var clock = this.clock
        clock.setAttribute("style","width:0;margin-left:0;margin-right:0;opacity:0")
        setTimeout(function(){           
            selectedCities.splice(selectedCities.indexOf(clock.id), 1)        
            container.removeChild(clock)
            activateOrderButton()
        },500)    
    } 
    setTimeout(function(){
        div.style.width= ""
        div.style.transform = ""        
        startClock(div)
       
    },10)
    
    selectedCities.push(cityName)
}
var selectedCities = []

var buttonOk = document.getElementById("buttonOk")
buttonOk.onclick = function(){
    var selectedCity = inputSearchCity.value    
    inputSearchCity.value =""
    inputSearchCity.style.color =""
    clearInput.style.display="none"
    this.disabled = true
    createHTMLclock(selectedCity)
    activateOrderButton()
}
var panel = document.getElementById("listCitysFound")
var inputSearchCity = document.getElementById("searchCity")
var clearInput = document.getElementById("clear")

clearInput.style.display ="none"
clearInput.onclick = function(){
    inputSearchCity.value="" 
    inputSearchCity.style.color =""
    panel.innerHTML=""
    this.style.display="none"
    buttonOk.disabled = true
    inputSearchCity.focus()
}

/*
inputSearchCity.onfocus = function(){
    scroll(0, document.getElementById("busqueLaCiutat").offsetTop-20)
    panel.style.display = ""
}
inputSearchCity.onblur = function(){
    setTimeout("panel.style.display = 'none'",200)
   
}
*/
inputSearchCity.onkeypress = function(event){    
    var char = String.fromCharCode(event.which || event.keyCode)
    if ((char<"a" || char>"z") && 
        (char<"A" || char>"Z") && 
        (char != "_")) return false
}
function clickCityList(city){
    inputSearchCity.value = city 
    panel.innerHTML = ""
    buttonOk.disabled = false
    inputSearchCity.style.color = "RoyalBlue"
}

inputSearchCity.oninput=function(){
   var value= this.value.trim().toUpperCase()
   panel.innerHTML=""
   var HTML = ""
   for (var i in city){
       if (selectedCities.indexOf(i) == -1 && value == i.toUpperCase().substr(0,value.length)){
           HTML += "<div onClick=clickCityList('"+i+"')>" +
            "<b>"  +i.substr(0,value.length)+ "</b>" +
                i.substring(value.length ) + 
               "<small> " +
               city[i].zone + " " +
               city[i].timezoneUTC +
                 "<\/small>" +
               "<\/div>"
           this.value= i.substr(0,value.length)          
        }
   }
   panel.innerHTML= HTML
   if (value.length == 0) {
       panel.innerHTML = ""
       clearInput.style.display="none"
   }else{
       clearInput.style.display=""
   }
   if (typeof city[this.value] != "undefined"){
       this.style.color ="RoyalBlue"
       panel.innerHTML=""
       buttonOk.disabled = false
   }else{
       this.style.color = ""
       buttonOk.disabled = true
   }

}
function get_the_time_in(option,callback){
    var xmlhttp = new XMLHttpRequest()
    var url = "https://www.icalendar37.net/gadgets/timeInTheCity/?q=" + option
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            callback(JSON.parse(xmlhttp.responseText))          
        }
    }
    xmlhttp.open("GET", url, true)
    xmlhttp.send()
} 
get_the_time_in("list",(obj)=>{
  city = obj
  inputSearchCity.disabled = false 
    ;["Apia","Adelaide","Bangkok","Dubai","Barcelona","London","Caracas","New_York","Los_Angeles","Marquesas","Pago_Pago"].forEach(function(city){       
      createHTMLclock(city)       
    })
}) 
window.addEventListener("focus",function(){
    //It is necessary to refresh the CSS animation if the page loses focus
    document.querySelectorAll(".clock").forEach(function(clock,i){
        startClock(clock)
    })
})
document.getElementById("fullscreen").onclick = function(){
    if(this.className=="fullscreen"){
        this.className="fullscreenOff"
        document.getElementById("fullscreenZone").requestFullscreen()
    }else{
        this.className="fullscreen"
        document.exitFullscreen()
    }
} 
              
            
!
999px

Console