dorien dorien - 2 months ago 18
Javascript Question

Preventing crosshair from moving on hover with flot

I have a plot drawn with flot in javascript.

I continuously set the crosshair position so that it is in sync with an audioPlayer.

this.crossHairPos = newAudioPosition;
this.setCrosshair({
x: this.crossHairPos
})


However, when I move my mouse over the plot the crosshair moves to my mouse. I think I should maybe use lockCrosshair, but I haven't succeeded yet:

lockCrosshair({x: this.crossHairPos});

Answer

This JSFiddle demonstrates setting, locking, and unlocking the crosshair without issue.

You'll want to use both the lockCrosshair and unlockCrosshair function:

$('#lock-crosshair').on('click', function() {
  plot.lockCrosshair({
    x: 4
  });
});

$('#unlock-crosshair').on('click', function() {
  plot.unlockCrosshair();
});