<svg> element fails to move when its position is updated during a mouse event

时间:2015-05-12 22:23:39

标签: javascript html css svg

Setting the left and top attributes of an clf = grid_search.best_estimator_.named_steps['svm'] print(clf.classes_) element, or a svg containing an div element fails when the call comes from inside a mouse event.

I have created a jsFiddle to illustrate this. Demo HTML page below for reference. Tested in Chrome, Firefox and Safari.

Is this the expected behaviour of svg elements?

I want to the user to be able to drag the svg elements around. How can I achieve this?


svg

1 个答案:

答案 0 :(得分:4)

You want header('Content-Type: text/html; charset=utf-8'); instead of event.target:

this

Fiddle

$dot = $(this) references the DOM element that initiated the event, in your case the event.target inside the SVG.

In the other hand, <circle> inside a jQuery event handler references the DOM element where the handler has been attached, that is, the this element where the event has fired.