Pen Settings

HTML

CSS

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

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

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.

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

              
                <div class="stage">
 
</div>

              
            
!

CSS

              
                html{
  font-family: 'Open Sans', sans-serif;
}
body{
  background-color:rgba(25,26,28, 1);
  overflow:hidden;
  
}
body, html {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

.stage{
  position:absolute;
  width:1024px;
  height:708px;
}
              
            
!

JS

              
                $( document ).ready(function() { 
  
       var body, stage, stageWidth, stageHeight, stageParent, isDevice;
              
       var USE_TILT, TILT_AMOUNT, INVERTED_TILT, GREEN_COLOR;
       

        function init (){

      
            TILT_AMOUNT = 20;
            USE_TILT = true;
            INVERTED_TILT = true;
            PERSPECTIVE = 650;
            GREEN_COLOR = 'rgba(0, 216, 245, 1)';
            OFF_WHITE_COLOR = 'rgba(255,255,239,1.00)';
            RED_COLOR = 'rgba(204, 50, 20, 1)';
            
            
            body = $("body");

      
            stage = $(".stage");

            TweenMax.set(stage, {
            	xPercent:-50,
            	yPercent:0,
            	left:'50%',
            	top:'0%'
            	})

            
            stageWidth = stage.width();
            stageHeight = stage.height();
      
            isDevice = (/android|webos|iphone|ipad|ipod|blackberry/i.test(navigator.userAgent.toLowerCase()));

            if(!isDevice){

              field = $('<div>Please run this in landscape on a device with an accelerometer</div>');
          
            } else {
              
              field = $('<div>Tilt your device in landscape mode  to rotate the clock</div>');              
            }
              TweenMax.set(field, {
                position:'absolute',
                y:100 ,
                width:stageWidth/2,
                xPercent:50,
                height:30,
                fontFamily:'Arial, Helvetica, sans-serif',
                fontSize:26,
                color:OFF_WHITE_COLOR,
                textAlign:'center',
                fontWeight:700
              });

              field.appendTo(stage);   

              TweenMax.delayedCall(4, function(){
                TweenMax.to(field, 2, {
                  alpha:0,
                  onComplete:function(){
                    field.remove();
                  }
                })
              })           
      
            analogueClockContainer = $('<div>');
            analogueClockWidth = 400;
            analogueClockHeight = 400;
            analogueClockDepth = 220;
            analogueClockHoursColor = OFF_WHITE_COLOR;
            analogueClockMinutesColor = OFF_WHITE_COLOR;
            analogueClockSecondsColor = RED_COLOR;
            analogueClockEdgeSize = 2;
      
      
            secondHandHeight = analogueClockWidth/2.7;
            minuteHandHeight = analogueClockWidth/2.9;
            hourHandHeight = analogueClockWidth/4;
            middleSize = 16;
            hourDotSize = 10;

            //containers
            mainContainer = $('<div>');
            sideContainer = $('<div>');
            analogueClockTop = $('<div>');


            //face      
            hourHand = $('<div>');
            minuteHand = $('<div>');
            secondHand = $('<div>');
            middle = $('<div>');
      
            TweenMax.set(middle, {
              position:'absolute',
              width:middleSize,
              height:middleSize,
              backgroundColor:analogueClockHoursColor,
              x:(analogueClockWidth/2) - (middleSize/2),
              y:(analogueClockHeight/2) - (middleSize/2),
              borderRadius:'50%'
            });
      
            TweenMax.set(secondHand, {
      
              position:'absolute',
              width:1,
              height:secondHandHeight,
              backgroundColor:analogueClockSecondsColor,
              transformOrigin:'50% 100%',
              x:(analogueClockWidth/2) - (1/2),
              y:(analogueClockHeight/2) - (secondHandHeight),
              outline:'1px solid transparent',
              alpha:0.5,
              boxShadow: "0px 0px 24px 6px rgba(155, 72, 74, 0.1)"
            })
      
            TweenMax.set(minuteHand, {
      
              position:'absolute',
              width:2,
              height:minuteHandHeight,
              backgroundColor:analogueClockMinutesColor,
              transformOrigin:'50% 100%',
              x:(analogueClockWidth/2) - (2/2),
              y:(analogueClockHeight/2) - (minuteHandHeight),
              outline:'1px solid transparent'//,
              //boxShadow: "0px 0px 24px 6px rgba(224, 233, 245, 0.1)"
            })
      
            TweenMax.set(hourHand, {
      
              position:'absolute',
              width:4,
              height:hourHandHeight,
              backgroundColor:analogueClockHoursColor,
              transformOrigin:'50% 100%',
              x:(analogueClockWidth/2) - (4/2),
              y:(analogueClockHeight/2) - (hourHandHeight),
              //webkitFilter:"blur(3px)"
              outline:'1px solid transparent'//,
              //boxShadow: "0px 0px 24px 6px rgba(255,255,255,0.1)"
            })
      
      
      
            TweenMax.set(mainContainer, {
      
              position:'absolute',
              width:analogueClockWidth,
              height:analogueClockHeight,
              x:(stageWidth/2) - (analogueClockWidth/2),
              y:(stageHeight/2) - (analogueClockHeight/2),
              transformStyle:'preserve-3d',
              perspective:PERSPECTIVE,
              borderRadius:'50%',
              transformOrigin:'50% 50% 0px'//,
              //z:-1250
      
            });

            TweenMax.set(analogueClockContainer, {
      
              position:'absolute',
              width:analogueClockWidth,
              height:analogueClockHeight,
              transformStyle:'preserve-3d',
              backfaceVisibility:'hidden',

              transformOrigin:'50% 50% 0px'//,
              //backgroundColor:'blue'
      
            });

            TweenMax.set(sideContainer, {
      
              position:'absolute',
              width:analogueClockWidth,
              height:analogueClockHeight,
              transformOrigin:'50% 50% 0px',
              transformStyle:'preserve-3d',
              rotationX:90
      
            });
      
      
            TweenMax.set(analogueClockTop, {
              position:'absolute',
              width:analogueClockWidth,
              height:analogueClockHeight,
              x:-(analogueClockEdgeSize/2),
              y:-(analogueClockEdgeSize/2),
              borderRadius:'50%',
              border:analogueClockEdgeSize + 'px solid rgba(115, 145, 150, 0.3)',
              z:(analogueClockDepth/2)
            })
      
            disc1 = analogueClockTop.clone();

            TweenMax.set(disc1, {
      
              z:analogueClockDepth/3,
              scale:0.05,
              x:analogueClockEdgeSize/2,
              y:analogueClockEdgeSize/2,
              border:'0px solid #ffffff',
              //backgroundColor:'rgba(115, 145, 150, 0.24)',
              alpha:0.12,
              backgroundColor:GREEN_COLOR
      
            })
      
            disc2 = analogueClockTop.clone();
            TweenMax.set(disc2, {
              x:analogueClockEdgeSize/2,
              y:analogueClockEdgeSize/2,
      
              z:analogueClockDepth/10,
              scale:0.1,
              border:'0px solid #ffffff',
              alpha:0.05,
              backgroundColor:GREEN_COLOR
      
            })
      
            disc3 = analogueClockTop.clone();
            TweenMax.set(disc3, {
              x:analogueClockEdgeSize/2,
              y:analogueClockEdgeSize/2,
      
              z:-analogueClockDepth/2,
              scale:0.52,
              border:'0px solid #ffffff',
              alpha:0.05,
              backgroundColor:GREEN_COLOR
      
            })



            disc1.appendTo(analogueClockContainer);
            disc2.appendTo(analogueClockContainer);
            disc3.appendTo(analogueClockContainer);
            analogueClockTop.appendTo(analogueClockContainer);
      
            minuteHand.appendTo(analogueClockTop);
            hourHand.appendTo(analogueClockTop);
            secondHand.appendTo(analogueClockTop);
            middle.appendTo(analogueClockTop);

            analogueClockContainer.appendTo(mainContainer);
            sideContainer.appendTo(analogueClockContainer);
            mainContainer.appendTo(stage);


      
            var numSides = 60;
            var sideWidth = 18;
            var i = numSides;
      
            //the sides of the cylinder
            while(--i > -1){
              var side = $('<div>');
              TweenMax.set(side, {
                position:'absolute',
                x:(analogueClockWidth/2) - (sideWidth/2) + (analogueClockEdgeSize/2),
                y:(analogueClockHeight/2) - (analogueClockDepth/2) + (analogueClockEdgeSize/2) + analogueClockDepth/4,
                width:sideWidth, 
                height:analogueClockDepth/1.5,
                backgroundColor:GREEN_COLOR,
                outline:'1px solid transparent',
                alpha:(i % 5) ? 0.01 : 0.03,
                alpha:0.03,
                transformOrigin:'50% 0% '+ (-analogueClockHeight/2)+'px',
                rotationY:(360/numSides) * i,     
                z:analogueClockHeight/2 - (analogueClockEdgeSize/2)
              })
      
              side.appendTo(sideContainer);
      
      
            }
      
            var numHourDots = 12;
            var i = numHourDots;
      
            while(--i > -1){

              var faceDotElement = $('<div>');
              var innerDot = $('<div>')
              innerDot.appendTo(faceDotElement);
             faceDotElement.appendTo(analogueClockContainer);

              TweenMax.set(innerDot, {
                position:'absolute',
                width:8,
                height:8,
                x:1,
                y:26,
                borderRadius:'50%',
                backgroundColor:'rgba(236,240,241,1)'
              })

              TweenMax.set(faceDotElement, {
                position:'absolute',
                width:10,
                height:analogueClockWidth/2,
                x:(analogueClockWidth/2) - (8/2),
                alpha:(i % 3) ? 0.5 : 1,    
                transformOrigin:'50% 100%',
                rotation:(360/numHourDots) * i,
                z:-analogueClockDepth/2
      
              })


              TweenMax.set(innerDot, {

                backgroundColor:(i % 3) ? GREEN_COLOR : OFF_WHITE_COLOR
      
              })
      
            }
      
           
     
            updateAnalogueClock();

            
            setTilt();

      
    }

    function setTilt (){
    

      if(isDevice){
    
        if(USE_TILT){
            
            if(INVERTED_TILT){

              TILT_AMOUNT *= -1;

            }

            window.addEventListener('devicemotion', onDeviceMotion, false);
            //dragger[0].disable();
    
    
        } else {
    
            window.removeEventListener('devicemotion', onDeviceMotion, false);
            //dragger[0].enable();
    
        }
    
      }
    }
    
    
    
    function onDeviceMotion (e){
    
        
      TweenMax.to(mainContainer, 0.4, {
    
        //tilt forwards/back
        rotationX:(-(e.accelerationIncludingGravity.x)*TILT_AMOUNT) + 90,
        //rotationX:(-(e.accelerationIncludingGravity.x)*TILT_AMOUNT) + 0,
    
        //tilt left/right
        rotationY:((e.accelerationIncludingGravity.y)*TILT_AMOUNT) + 0,
        ease:Power1.easeInOut,
        force3D:true
      })
    
    }
    
    
    
     function updateAnalogueClock(){
    		
       //console.log('updateAnalogueClock')
        var myDate = new Date();
    
           //hours minutes and seconds from Date object
        var hours = myDate.getHours();
        var minutes = myDate.getMinutes();
        var seconds = myDate.getSeconds();
        var sdegree = seconds * 6;
    
           //minute position calculation
        var minuteValue = minutes*6;
        TweenMax.to(minuteHand, 0.6,{ 
          shortRotation:minuteValue,
          force3D:true,
         ease:Back.easeOut});
    
           //hour position calculation
        var hourValue = hours*30 +(minutes/2);         
        TweenMax.to(hourHand, 0.6, {shortRotation:hourValue});
        //TweenMax.fromTo(secondHand, 60, {rotation:0},{rotation:360, onComplete:updateAnalogueClock, ease:Linear.easeNone});
    
        TweenMax.to(secondHand, 0.6,{
    
          shortRotation:sdegree,
          force3D:true,
          ease:Elastic.easeOut.config(0.6)
        });
    
        TweenMax.delayedCall(1, updateAnalogueClock);
    
    
    
     }

     init();
})
              
            
!
999px

Console