example.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>&laquo;TimeTo&raquo; jQuery plug-in example</title>
  6. <!--[if lt IE 9]>
  7. <script>
  8. document.createElement('figure');
  9. document.createElement('figcaption');
  10. </script>
  11. <![endif]-->
  12. <link href="timeTo.css" type="text/css" rel="stylesheet"/>
  13. <style>
  14. pre {
  15. margin-bottom: 10px;
  16. padding-left: 10px;
  17. border-left: 3px #DDD solid;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <h1>&laquo;TimeTo&raquo; jQuery plugin demo</h1>
  23. <h2>Countdown timer</h2>
  24. <h3>Set delay in seconds</h3>
  25. <pre>
  26. $('#countdown').timeTo(120, function(){ alert('Countdown finished'); }); </pre>
  27. <div id="countdown-1"></div>
  28. <p><button id="reset-1" type="button">Reset</button></p>
  29. <div class="clock"></div>
  30. <div class="clock"></div>
  31. <h3>Hide hours</h3>
  32. <pre>
  33. $('#countdown').timeTo({
  34. seconds: 100,
  35. displayHours: false
  36. }); </pre>
  37. <div id="countdown-11"></div>
  38. <h3>Set delay to specyfied datetime</h3>
  39. <pre>
  40. $('#countdown').timeTo(new Date('<span id="date-str"></span>')); </pre>
  41. <div id="countdown-2"></div>
  42. <h3>Set captions and dark theme</h1>
  43. <pre>
  44. $('#countdown').timeTo({
  45. timeTo: new Date(new Date('<span id="date2-str"></span>')),
  46. displayDays: 2,
  47. theme: "black",
  48. displayCaptions: true,
  49. fontSize: 48,
  50. captionSize: 14
  51. }); </pre>
  52. <div id="countdown-3"></div>
  53. <p>&nbsp;</p>
  54. <h2>Digital clock</h2>
  55. <pre>
  56. $('#clock-1').timeTo();</pre>
  57. <div id="clock-1"></div>
  58. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  59. <script>window.jQuery || document.write('<script src="node_modules/jquery/dist/jquery.min.js"><\/script>')</script>
  60. <script src="jquery.time-to.js"></script>
  61. <script>
  62. /**
  63. * Set timer countdown in seconds with callback
  64. */
  65. $('#countdown-1').timeTo(120, function(){
  66. alert('Countdown finished');
  67. });
  68. $('#reset-1').click(function() {
  69. $('#countdown-1').timeTo('reset');
  70. });
  71. /**
  72. * Hide hours
  73. */
  74. $('#countdown-11').timeTo({
  75. seconds: 100,
  76. displayHours: false
  77. });
  78. var date = getRelativeDate(20);
  79. document.getElementById('date-str').innerHTML = date.toString();
  80. /**
  81. * Set timer countdown to specyfied date
  82. */
  83. $('#countdown-2').timeTo(date);
  84. date = getRelativeDate(7, 9);
  85. document.getElementById('date2-str').innerHTML = date.toString();
  86. /**
  87. * Set theme and captions
  88. */
  89. $('#countdown-3').timeTo({
  90. timeTo: date,
  91. displayDays: 2,
  92. theme: "black",
  93. displayCaptions: true,
  94. fontSize: 48,
  95. captionSize: 14
  96. });
  97. /**
  98. * Simple digital clock
  99. */
  100. $('#clock-1').timeTo();
  101. function getRelativeDate(days, hours, minutes){
  102. var date = new Date((new Date()).getTime() + 60000 /* milisec */ * 60 /* minutes */ * 24 /* hours */ * days /* days */);
  103. date.setHours(hours || 0);
  104. date.setMinutes(minutes || 0);
  105. date.setSeconds(0);
  106. return date;
  107. }
  108. </script>
  109. </body>
  110. </html>