visjs / vis-timeline

📅 Create a fully customizable, interactive timelines and 2d-graphs with items and ranges.
https://visjs.github.io/vis-timeline/
Other
1.85k stars 311 forks source link

Is there a way to show a cursor when mouse is hover on the timeline #1678

Open PorterNan opened 1 year ago

PorterNan commented 1 year ago

Hi! I've been using timeline for a while and it's been amazing, and now I am trying to implement a cursor(all across groups) and follow the mouse when hovering on timeline all the time. The way I was planning to implement it is:

  1. Listen to mouse hover event on timeline
  2. Get the time stamp
  3. set current time

But I noticed for 1, it only works when you hover on an item not the timeline itself, so wondering if there is a better/simpler way to implement this .

esemplare commented 1 year ago

Use mouseMove event to receive an event when the mouse moves within the timeline. See time and snappedTime properties of the event.

timeline.on("mouseMove", onMouseMove)

PorterNan commented 1 year ago

yea... I usied that event, but it feels that event only triggered when mouse is on a item, lemme double check if I just got a wrong memory

PorterNan commented 1 year ago

Just validated that and it works! Thanks for sharing that code snippet, there is one more interesting question comes up now, when I call timelineInstance?.addCustomTime(event.time); it create a dragabble line which always stay under my mouse, so I can do any other operation like click and drag for other items

Is there a solution for this?

setCurrentTime looks fine, but it is moving all the time, if there is a way to pause it as it is, that would be nice as well!