Staafsak Staafsak - 5 months ago 16
Javascript Question

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!

Answer

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.

Comments