javascript - angularjs - mousedown & moving over elements while mouse down event? - Stack Overflow

To explain what I am trying to do I have created an example where you can play with:I want to draw mult

To explain what I am trying to do I have created an example where you can play with:

I want to draw multiple tiles green while my mouse is down. This:

<div ng-mousedown="drawImage($parent.$index,$index)"></div>

works only when the mouse is going down on the element not outside.

Is there an way to check if the mouse is already down and draw the tiles green?

Please use the code I made to create an working example.

To explain what I am trying to do I have created an example where you can play with:

http://plnkr.co/edit/usrmiNkj5YJY5SlV8ETw?p=preview

I want to draw multiple tiles green while my mouse is down. This:

<div ng-mousedown="drawImage($parent.$index,$index)"></div>

works only when the mouse is going down on the element not outside.

Is there an way to check if the mouse is already down and draw the tiles green?

Please use the code I made to create an working example.

Share Improve this question asked Aug 9, 2014 at 21:12 IsmailIsmail 9,6223 gold badges23 silver badges39 bronze badges 2
  • Don't do it with angular ngWhatever. Write your custom directive to handle onmouseover, onmousedown, etc events. – dfsq Commented Aug 9, 2014 at 21:17
  • @dfsq Can you create an working example? – Ismail Commented Aug 9, 2014 at 21:53
Add a ment  | 

1 Answer 1

Reset to default 4

You'll have to include a few more event handlers, for mouseup and mousemove, like this

<div class="tile" ng-repeat="x in y track by $index" ng-class="x" ng-mouseup="removeFlag()" ng-mousedown="setFlag($parent.$index,$index)" ng-mousemove="drawImage($parent.$index,$index)"></div>

Then add the functions

$scope.drawImage = function(y,x){
  if ($scope.mouseIsDown)
    $scope.map[y][x] = "green";
}

$scope.setFlag = function(y,x){
   $scope.mouseIsDown = true;
   this.drawImage(y,x)
}

$scope.removeFlag = function(){
   $scope.mouseIsDown = false;
}

This sets a flag when the mouse is down, and sets the color when the cursor moves over an element and the mouse is down.

PLNKR

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745200590a4616302.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信