简体   繁体   English

单击按钮后如何检测mousemove事件

[英]How to detect mousemove event on after button click

I have a div. 我有一个div。 I click on the div and move the cursor without releasing the mouse button. 我单击div并在不释放鼠标键的情况下移动光标。 In this case mousemove event not working. 在这种情况下,mousemove事件不起作用。 How to detect the change in position of cursor..... 如何检测光标位置的变化.....

My sample code is below 我的示例代码如下

$scope.volhandlerclick=function($event)
    {
        $scope.volhandclick=true;
        oldPos=angular.element($event.target).prop('offsetLeft');
        angular.element($event.target).bind("mousemove",function(obj)
        {

            console.log(obj.pageX)

        })      

    };

The click event only fires after you release the mouse button. 仅在释放鼠标按钮后才会触发click事件。 You'll need to use ng-mousedown instead of ng-click . 您需要使用ng-mousedown而不是ng-click

well you can always do it with ngClick and ngMouseMove... like this 好吧,您始终可以使用ngClick和ngMouseMove ...像这样

Jsfiddle 杰斯菲德尔

<div ng-app="myApp">
<div ng-controller="myController">
    <div class="rectangle" ng-mousemove="mouseMove()" ng-click="click()">{{message}}</div>
    {{count}}
</div>

 angular.module('myApp', ['ngTouch'])
    .controller('myController', ['$scope', function ($scope) {
       $scope.message = "Mouse click and move!";
        $scope.count = 0;
        $scope.click = function() {
            $scope.isClicked = true;
        }; 
        $scope.mouseMove = function(){
            if($scope.isClicked){
        $scope.count++;
            }
        };        
}]);

so the fist event is triggered by the click and then you handle everything via mouse move... if you want the offset and what not just pass the $event to the function. 因此,第一个事件是通过单击触发的,然后您可以通过鼠标移动来处理所有事情……如果您想要偏移量,而不仅仅是将$ event传递给函数。

or something like that 或类似的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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