简体   繁体   中英

How to detect mousemove event on after button click

I have a div. I click on the div and move the cursor without releasing the mouse button. In this case mousemove event not working. 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. You'll need to use ng-mousedown instead of ng-click .

well you can always do it with ngClick and ngMouseMove... like this

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.

or something like that

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