很棒的时间线ui控件(纯javascript)

开发 前端
为了减少计算次数,用户操作时把图文面板,时间点,还有时间的位置信息都储存起来,这样在用户操作时计算并储存,第二次操作时读取缓存的位置信息。

效果预览:

在线预览:传送门

时间练利用两个时间之间的差别与整个时间轴的长度运算得来

  1. locateHandler = function () {   
  2.         var referTime = (that[that.length] - that[0]) / 86400000, i = 0, len = that.handler.length, temp = 0;   
  3.         for (; i < len;) {   
  4.             temp = ((that[i] - that[0]) / (referTime * 86400000)) * that.parent.offsetWidth;   
  5.             that.fx(that.handler[i], 'left', ((i === len - 1 || i === 0) ? temp - 20 : temp), 50);   
  6.             i++;   
  7.         } 

为了减少计算次数,用户操作时把图文面板,时间点,还有时间的位置信息都储存起来,这样在用户操作时计算并储存,第二次操作时读取缓存的位置信息。直接用css设置位置减少运算量

cache = [[],[],[]]

初始化时只有一组信息

触摸了2个时间点以后,位置数据已经被缓存起来了

  1. if (!indicator.cache[1][index]) {   
  2.     if ((rect.left - div.offsetWidth / 2) < limit.left) {   
  3.         indicator.cache[1][index] = 'visibility:visible;left:0px;';   
  4.     } else if ((rect.left + div.offsetWidth / 2) > limit.right) {   
  5.                 indicator.cache[1][index] = 'visibility:visible;left:' + (limit.right - div.offsetWidth - limit.left) + 'px;';   
  6.     } else {   
  7.         indicator.cache[1][index] = 'visibility:visible;left:' + (rect.left - div.offsetWidth / 2 - limit.left) + 'px;';   
  8.     }   
  9.                 

图文面板的位置也是经过智能计算获取,如果超出左边则左对齐,其他情况则以时间点位参考居中,右边超出亦然

动画使用了tween的一些算法 可以自己修改。

原文链接:http://www.cnblogs.com/enix/archive/2012/06/27/2565568.html

【编辑推荐】

责任编辑:张伟 来源: 小玉西瓜的博客
相关推荐

2021-07-24 13:40:25

谷歌Chrome浏览器

2011-09-26 11:17:16

2018-08-06 09:18:33

Windows操作系统Chrome

2015-08-26 13:49:06

可视化

2022-03-09 12:45:15

时间线

2024-02-21 12:15:00

SoraOpenAI人工智能

2017-11-22 19:30:58

Windows时间线功能完整版

2019-04-26 14:30:49

自动驾驶Uber特斯拉

2021-04-15 21:57:49

Windows 10Windows微软

2019-11-18 14:50:29

开发技能代码

2014-06-18 10:53:44

BootstrapBootstrap U

2024-04-01 08:48:38

Node.jsnpmNode

2021-01-19 12:16:10

CSS前端UI

2020-12-31 07:56:02

JavaScript 字符串技巧

2021-05-26 05:24:51

Windows10操作系统微软

2023-04-17 16:19:32

编程语言JavaScript开发

2023-02-09 16:15:27

JavaScript编程语言字符串

2020-03-08 13:24:47

JavaScript开发

2020-07-25 19:38:54

JavaScriptJavaScript库Web

2023-02-24 09:54:54

开源React
点赞
收藏

51CTO技术栈公众号