Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS Change Class on ng-mouseover

Am trying to add a class (blue) to a button when ever you hover the button using AngularJS.

HTML

<button class="btn-add-optimize" ng-mouseover="hover(iets)">Add and Optimize</button>

AngularJS

$scope.hover = function (iets) {
    var Dit = this;
    Dit.add("blue");
};

Anyone can help me out? Preferable a small example, it would be very appreciated!

like image 588
Staafsak Avatar asked Dec 09 '14 04:12

Staafsak


1 Answers

I've used something like this with success:

<button
    ng-class="{'some-class':hovering}"
    ng-mouseenter="hovering=true"
    ng-mouseleave="hovering=false">Add and Optimize</button>

Entering and leaving the button toggles $scope.hovering, and the application of some-class is contingent on the $scope.hovering scope variable being true.

like image 149
Collin Allen Avatar answered Sep 19 '22 09:09

Collin Allen