Gas Pump Style Clock with jQuery

Gas Pump Style Clock with jQuery
File Size: 1.91MB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A javascript library for jQuery that helps you create an animated clock in the style of Gas Pump.  Please Check the demo before moving on.

More Demos:

How to use it:

1. Include jQuery library in your head section

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

2. Javascript

<script type="text/javascript">

  $(document).ready(function(){

    $('#wrap').animate({opacity: 0.0}, 0);
    
    function middle(){

      wrapTop = ($(window).height() - $('#wrap').height())/2;
      wrapLeft = ($(window).width() - $('#wrap').width())/2;

      $('#wrap').animate({marginTop: wrapTop, marginLeft: wrapLeft}, 500);

    };

      middle();

      $(window).bind('resize', middle);

    function checktime(prevhour,prevmins,prevsecs){

      var now = new Date();

      var hour = now.getHours();
      if(hour < 10) hour = "0" + hour;

      var mins = now.getMinutes();
      if(mins < 10) mins = "0" + mins;

	var secs = now.getSeconds();
	if(secs < 10) secs = "0" + secs;  

      var hour = hour + "";
      var mins = mins + "";
	var secs = secs + "";

      if(prevhour != hour) {

        var prevhour = prevhour + ""
        var hoursplit = hour.split("");
        var prevhoursplit = prevhour.split("");

        if(prevhoursplit[0] != hoursplit[0]) numberflip('#hourl',hoursplit[0]);
        if(prevhoursplit[1] != hoursplit[1]) numberflip('#hourr',hoursplit[1]);

      };

      if(prevmins != mins) {

        var prevmins = prevmins + ""
        var minsplit = mins.split("");
        var prevminsplit = prevmins.split("");

        if(prevminsplit[0] != minsplit[0]) numberflip('#minl',minsplit[0]);
        if(prevminsplit[1] != minsplit[1]) numberflip('#minr',minsplit[1]);

      };

      if(prevsecs != secs) {

        var prevsecs = prevsecs + ""
        var secsplit = secs.split("");
        var prevsecsplit = prevsecs.split("");

        if(prevsecsplit[0] != secsplit[0]) numberflip('#secl',secsplit[0]);
        if(prevsecsplit[1] != secsplit[1]) numberflip('#secr',secsplit[1]);

      };

      function numberflip(which,number){

		if(number != 0) $(which).animate({marginTop: '-'+parseInt((number*140),10)+'px'}, 250, 'linear');

		if(number == 0) {

              var getmargin = parseInt(($(which).css('margin-top')), 10);

              $(which).animate({marginTop: parseInt((getmargin-140),10)+'px'}, 250, 'linear', function(){
                $(this).css("margin-top","0px")
		  });

            };

      };

      setTimeout(function(){checktime(hour,mins,secs);}, 200);

    };

    checktime(00,00,00);

    $('#wrap').animate({opacity: 1.0}, 1000);

  });

</script>

3. The CSS

#wrap {
position: relative;
width: 680px;
height: 140px;
background: url(black.png);
border: solid 1px #000;
text-align: left;
overflow: hidden;
}
#wrap img.time {
float: left;
}
#wrap #cover {
position: absolute;
top: 0;
left: 0;
width: 680px;
height: 140px;
background: url(fade.png) repeat-x;
}
*html body #wrap #cover {
width: 0px;
height: 0px;
}

4. Markup

<div id="wrap"> 
<img id="hourl" class="time" src="nums2.png" /> 
<img id="hourr" class="time" src="nums10.png" /> 
<img class="time" src="colon.png" /> 
<img id="minl" class="time" src="nums6.png" /> 
<img id="minr" class="time" src="nums10.png" /> 
<img class="time" src="colon.png" /> 
<img id="secl" class="time" src="nums6.png" /> 
<img id="secr" class="time" src="nums10.png" />
<div style="clear:left;"></div>
<div id="cover"></div>
</div>

This awesome jQuery plugin is developed by unknown. For more Advanced Usages, please check the demo page or visit the official website.