forked from zafarali/learning-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-2-directives.html
57 lines (51 loc) · 1.38 KB
/
03-2-directives.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
<title>directives</title>
<style>
*{font-family: Tahoma; font-size: 1em;}#wrapper{width:100%;};
#inner{width:50%; margin:0 auto; border:solid black 1px;};
</style>
<script src="http://cdn.bootcss.com/angular.js/1.2.17/angular.min.js"></script>
<script>
var app = angular.module("usefulDirectives", []);
app.directive("enter", function(){
//by default this is of restrict:'A'
return function(scope, element, attrs){
element.bind("mouseenter", function(){
element.removeClass(attrs.class)
element.addClass(attrs.enter);
});
};
});
app.directive("leave", function(){
//by default this is of restrict:'A'
return function(scope, element,attrs){
element.bind("mouseleave", function(){
element.removeClass(attrs.class);
element.addClass(attrs.leave);
});
};
});
</script>
<!--The following is style we are going to use in our manipulations-->
<style>
.green{
background-color: green;
border:1px solid black;
}
.hover{
background-color:red;
border:1px solid black;
}
.warnOrange{
background-color: orange;
border:1px solid black;
}
</style>
</head>
<body ng-app="usefulDirectives">
<div enter="hover" leave="warnOrange" class="warnOrange">THIS IS VERY IMPORTANT! ROLL OVER!</div><br />
<div enter="hover" leave="warnOrange" class="green">This is not important until you roll over!</div>
</body>
</html>