Mousedown not working with vis timeline

284 views Asked by At

I have a problem with mousedown event join to a vis timeline map...

This is the structure of my code :

<div id="firstDiv">
   <div id="timelineMap"></div>
</div>

$("#firstDiv").mousedown(function (e) {
    console.log("mouseDown");

    initialW = e.pageX;
    initialH = e.pageY;

    $("#firstDiv").bind("mouseup", function1);
    $("#firstDiv").bind("mousemove", function2);
    }
});

But when I click on the firstDiv nothing is happening. I think that the problem is inside the timelineMap because without it mousedown works... inside that div there is the vis timeline map. The strange thing is that if I use click() instead of mousedown it works but obviously in that case I can't use mouseup.

Please help me to figure out

1

There are 1 answers

1
Zakaria Acharki On

As of jQuery 3.0, .bind() has been deprecated. It was superseded by the .on() method for attaching event handlers to a document since jQuery 1.7, so its use was already discouraged.

Try to use on() instead :

$("#firstDiv").on('mousedown', function (e) {
    console.log("mouseDown");
    initialW = e.pageX;
    initialH = e.pageY;
});

$("#firstDiv").on("mouseup", function1);
$("#firstDiv").on("mousemove", function2);

NOTE : You've an extra } in your posted code.

Hope this help.