简体   繁体   中英

binding predefined functions to Jquery events

I have a working script to apply transformations to SVG so that the image is draggable. The script works when I use the attributes of the html element.

<g id="all" onmousedown="startMove(evt)" onmousemove="moveIt(evt)" onmouseup="endMove(evt)">

However I would like to bind the events with Jquery something like below and wonder where I am going wrong with the code below

$('svg > g').mousedown(startMove(evt));
$('svg > g').mousemove(moveIt(evt));
$('svg > g').mouseup(endMove(evt));

Try this:

$('svg > g').mousedown(function(evt){
    //do stuff
});

or even

$('svg > g').mousedown(startMove);

function startMove(evt){
    //do stuff
}

startMove references the actual function, while startMove() uses it's return value.

I believe you have to do it like so:

$('svg > g').mousedown(function(evt){
    startMove(evt);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM