项目作者: kayfairy

项目描述 :
HTML5 date time input element - round date
高级语言: JavaScript
项目地址: git://github.com/kayfairy/round-date-selector.git
创建时间: 2019-01-09T14:01:19Z
项目社区:https://github.com/kayfairy/round-date-selector

开源协议:GNU General Public License v3.0

下载


Round Date Selector

image

Drag pointers until desired date and time gets displayed.

https://jsfiddle.net/3j2gpqsy

Usage

Change values at start, setting the data attributes for each canvas or setting the option start.

  1. <div id="calendar-container-id" class="round-date-selector" data-year="2013" data-month="4" data-day="16">
  2. [...]
  3. </div>
  4. <div id="clock-container-id" class="round-date-selector" data-hour="8" data-minute="13">
  5. [...]
  6. </div>
  7. <script>
  8. var dateSlider = DateSlider('calendar-container-id', {option: 'value'});
  9. var clockSlider = ClockSlider('clock-container-id', {option: 'value'});
  10. </script>

Options

Option start can contain values accepted by Date.parse(). start option of Clockslider does not need a preceding date.

Set locale option to change language. Valid options are parameters of Date.toLocaleDateString().

Add format option if necessary. Following characters inside the format string get replaced:

format character value
d day [01-31]
m month [01-12]
y year
b month short name [Jan-Dec]
B month long name [January-December]
a day short name [Mon-Sun]
A day long name [Monday-Sunday]
H hour [00-23]
M minute [00-59]

Events available are onMove and onChange.

  1. DateSlider(
  2. 'calendar-container-id',
  3. {
  4. start: '21 Oct 2011',
  5. locale: ['en-US', {weekday: 'short', year: 'numeric', month: 'short', day: 'numeric'}],
  6. format: 'a, d. b y',
  7. onChange: function (event) {
  8. console.log(event.value, event.day, event.month, event.year);
  9. }
  10. }
  11. );
  12. ClockSlider(
  13. 'clock-container-id',
  14. {
  15. start: '00:00',
  16. format: 'Hh Mm',
  17. onMove: function (event) {
  18. event.preventDefault();
  19. console.log(event.value, event.hour, event.minute);
  20. }
  21. }
  22. );

Form values

Selected date and time values are stored inside input fields as ISO 8601 format. Years from 1 to 9999.

  1. <input class="date-input" type="hidden" name="date" value="2013-08-14">
  2. <input class="clock-input" type="hidden" name="time" value="03:00">

Appearance

Modify colors by changing svg attributes stroke, fill and setting options c1slidecolor, c2slidecolor on ClockSlider.

  1. <circle cx="105" cy="105" r="80" stroke="darkolivegreen" stroke-width="1" fill="white" ></circle>
  2. <script>
  3. ClockSlider(
  4. 'clock-container-id',
  5. {
  6. c1slidecolor: 'rgba(56, 131, 37, 1)',
  7. c2slidecolor: 'rgba(194, 25, 25, 1)'
  8. }
  9. );
  10. </script>

Show current time

Disable selector and adjust current time every 1 second.

  1. var dateSlider = DateSlider('calendar-container-id', {
  2. onMove: function (event) {
  3. event.preventDefault();
  4. }
  5. });
  6. var clockSlider = ClockSlider('clock-container-id', {
  7. onMove: function (event) {
  8. event.preventDefault();
  9. }
  10. });
  11. function setDate(date) {
  12. clockSlider.hour = date.getHours();
  13. clockSlider.minute = date.getMinutes();
  14. clockSlider.update();
  15. dateSlider.day = date.getDate();
  16. dateSlider.month = date.getMonth();
  17. dateSlider.year = date.getFullYear();
  18. dateSlider.update();
  19. }
  20. setDate(new Date());
  21. setInterval(function () { setDate(new Date()); }, 1000);

License

GPLv3 License