javascript events - How to focus automatically on the current date in vis.js timeline -


i wrote program uses vis.js timeline , focuses on current date on click of button:

<button type="button" class="btn btn-info" onclick="timeline.focus(0)">focus on current date</button>

where

var timeline = new vis.timeline(container, data, options);

and

var data = [ //create item in dataset corresponding current date {id: 0, content: 'today', start: date()},...];

now timeline focus automatically on current date when user changes range. tried use rangechange event:

timeline.on('rangechange', function (properties) { timeline.focus(0); });,

but focusing not occur expected.

would please me understand what's going on , how implement functionality?

rangechange gets fired multiple times, every time timeline changes, when timeline animating, trying focus on specific event keeps firing rangechange event. there couple of solutions problem.

  1. you check byuser property of properties object , trigger focus when true (the user zoomed or scrolled in timeline), prevent jumping around erratically. replace current event listener with

    timeline.on('rangechange', function(properties) {     if (properties.byuser) {         timeline.focus(0);     } }); 
  2. simply use rangechanged event, gets fired once each timeline change. if plan have range changes not user driven event should use. again, change simple , need change event listener to

    timeline.on('rangechanged', function(properties) {     timeline.focus(0); }); 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -