我有以下HTML代码。目标是让图像跟随鼠标直到你点击它。单击后,鼠标后面的图像将保持在该位置。
<div ng-app="circleApp" ng-controller="CircleController">
<svg ng-click="draw($event)" ng-mouseover="drag($event)" width="40%" height="90%">
<image id="kort" sketch:type="MSBitmapLayer" width="100%" height="100%" xlink:href="/images/Germany.jpg"></image>
<g ng-repeat="ele in elements">
<g ng-switch on="ele.type">
<image ng-switch-when="0"
x="{{ele.x}}"
y="{{ele.y}}"
class="{'focus':ele.f===1}"
width="10%"
height="10%"
xlink:href="/images/pretzl.png"></image>
</g>
</g>
<g ng-repeat="ele in finalelement">
<g ng-switch on="ele.type">
<image ng-switch-when="0"
x="{{ele.x}}"
y="{{ele.y}}"
class="{'focus':ele.f===1}"
width="10%"
height="10%"
xlink:href="/images/pretzl.png"></image>
</g>
</g>
这应该触发以下文件中的两个函数之一:
angular.module("circleApp", [])
.controller("CircleController", CircleController);
function CircleController($scope, $interval) {
$scope.elements = [];
$scope.finalelement = [];
$scope.currentTool = 0;
$scope.x = 0;
$scope.y = 0;
$scope.draw = function(e) {
if ($scope.finalelement.length < 1) {
$scope.finalelement.push({
"type" : $scope.currentTool,
"x" : $scope.x - 55,
"y" : $scope.y - 25,
});
}
};
$scope.drag = function(e) {
if ($scope.finalelement.length < 2) {
$scope.elements = [];
if ($scope.elements.length < 1) {
$scope.x = e.offsetX;
$scope.y = e.offsetY;
$scope.elements.push({
"type" : $scope.currentTool,
"x" : $scope.x - 55,
"y" : $scope.y - 25,
});
}
}
};
}
但是,它只触发拖动功能。有人知道我错过了什么吗?