渐进增强时间线插件 jQuery时间戳

  • 源码大小:17.07KB
  • 所需积分:1积分
  • 源码编号:19JP-3735
  • 浏览次数:1002次
  • 最后更新:2023年07月17日
  • 所属栏目:图表
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

Timestack是一个响应迅速、灵活、渐进的增强时间线插件,用于按时间顺序显示项目事件

它可以用于在时间线界面上将项目进度可视化为条形图,因此我们也可以将其称为简化甘特图。

如何使用它:

1.在文档中加载所需的jQuery和moment.js库。

  1. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  2. <script src="/path/to/cdn/moment.min.js"></script>

2.从数据对象生成一个简单的时间线。

  1. <div id="timeline"></div>
  1. $(function(){
  2. $('#timeline').timestack({
  3. span: 'hour',
  4. data: [
  5. {
  6. start: '2022-08-26T09:00',
  7. end: '2022-08-26T17:00',
  8. title: 'Bob OOO',
  9. content: "<p>He's in the Bahamas or something.</p> <h2>Lucky bastard.</h2>",
  10. color: 'rgb(149, 203, 255)'
  11. },
  12. {
  13. start: '2022-08-26T09:00',
  14. end: '2022-08-26T10:00',
  15. title: 'Meeting',
  16. color: 'rgb(255, 149, 192)'
  17. },
  18. {
  19. start: '2022-08-26T12:00',
  20. end: '2022-08-26T13:00',
  21. title: 'Lunch',
  22. content: "<p>Nom nom at <a href='http://www.cloverfoodlab.com/'>Clover</a>.</p>",
  23. color: 'rgb(151, 255, 177)'
  24. },
  25. {
  26. start: '2022-08-26T12:30',
  27. end: '2022-08-26T15:30',
  28. title: 'Code review',
  29. content: "<p>Gotta find out if everyone is happy with this timeline component.<p>",
  30. color: 'rgb(255, 149, 192)'
  31. }
  32. ]
  33. });
  34. });

3.从HTML列表中生成渐进增强时间线,其中使用数据属性:

  1. <div id="timeline">
  2. <ul>
  3. <li data-start="2022-08-26T09:00" data-end="2022-08-26T17:00" data-color="#95e6ff">Bob OOO</li>
  4. <li data-start="2022-08-26T09:00" data-end="2022-08-26T10:30" data-color="#ff95c0">Meeting</li>
  5. <li data-start="2022-08-26T12:00" data-end="2022-08-26T13:00" data-color="#97ffb1">Lunch</li>
  6. <li data-start="2022-08-26T13:00" data-end="2022-08-26T14:30" data-color="#ff95c0">
  7. Code review
  8. <p>Gotta find out if everyone is happy with this timeline component.<p>
  9. </li>
  10. </ul>
  11. </div>
  1. $(function(){
  2. $('#timeline').timestack({
  3. span: 'hour',
  4. });
  5. });

4.此示例显示了如何在单击时间线时显示事件详细信息。

  1. <div id="display">
  2. <h1 id="title"></h1>
  3. <h3 id="dates"></h3>
  4. <div id="content"/>
  5. </div>
  1. $(function(){
  2. $('#timeline').timestack({
  3. span: 'hour',
  4. click: function(data){
  5. $('#title').text(data.title);
  6. $('#dates').text(data.timeDisplay);
  7. $('#content').empty().append(data.content);
  8. }
  9. });
  10. });

5.这个例子展示了如何使用twix.js库对时间范围进行更精细的格式化。

  1. <script src="/path/to/cdn/twix.min.js"></script>
  1. $(function(){
  2. $('#timeline').timestack({
  3. span: 'hour',
  4. click: function(data){
  5. $('#title').text(data.title);
  6. $('#dates').text(data.timeDisplay);
  7. $('#content').empty().append(data.content);
  8. },
  9. renderDates: function(item){
  10. return moment(item.start).twix(item.end).format({showDate: false})
  11. },
  12. data: [
  13. {
  14. start: '2012-08-26T09:00',
  15. end: '2012-08-26T17:00',
  16. title: 'Bob OOO',
  17. content: "<p>He's in the Bahamas or something.</p> <h2>Lucky bastard.</h2>",
  18. color: 'rgb(149, 203, 255)'
  19. },
  20. {
  21. start: '2012-08-26T09:00',
  22. end: '2012-08-26T10:00',
  23. title: 'Meeting',
  24. color: 'rgb(255, 149, 192)'
  25. },
  26. {
  27. start: '2012-08-26T12:00',
  28. end: '2012-08-26T13:00',
  29. title: 'Lunch',
  30. content: "<p>Nom nom at <a href='http://www.cloverfoodlab.com/'>Clover</a>.</p>",
  31. color: 'rgb(151, 255, 177)'
  32. },
  33. {
  34. start: '2012-08-26T12:30',
  35. end: '2012-08-26T15:30',
  36. title: 'Code review',
  37. content: "<p>Gotta find out if everyone is happy with this timeline component.<p>",
  38. color: 'rgb(255, 149, 192)'
  39. }
  40.  
  41. ]
  42. });
  43. });

6.具有默认值的完整插件选项。

  1. $('#timeline').timestack({
  2.  
  3. // click handler
  4. click: function() {},
  5.  
  6. // date parser
  7. parse: function(s) {
  8. return moment(s);
  9. },
  10.  
  11. // determine how to render dates
  12. renderDates: function(item) {
  13. var dateFormat, endFormated, startFormated;
  14. dateFormat = this.dateFormats[options.span];
  15. startFormated = item.start.format(dateFormat);
  16. endFormated = item.tilNow ? '' : item.end.format(dateFormat);
  17. return this.formatRange(startFormated, endFormated);
  18. },
  19.  
  20. // foramt date ranges
  21. formatRange: function(startStr, endStr) {
  22. return "" + startStr + " - " + endStr;
  23. },
  24.  
  25. // 'year', 'month', 'day', 'hour'
  26. span: 'year',
  27.  
  28. // date formats
  29. dateFormats: {
  30. year: 'MMM YYYY',
  31. month: 'MMM DD',
  32. day: 'MMM DD',
  33. hour: 'h:mm a'
  34. },
  35. intervalFormats: {
  36. year: 'YYYY',
  37. month: 'MMM YYYY',
  38. day: 'MMM DD',
  39. hour: 'h:mm a'
  40. }
  41. });

预览截图