Skip to content

Commit e13e70a

Browse files
committed
Update test code
1 parent b3fa93b commit e13e70a

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ AnimEvent controls timing of calling event listeners with [`requestAnimationFram
1010

1111
AnimEvent works like [lodash's `throttle` function](https://lodash.com/docs#throttle), but it uses `requestAnimationFrame` that is more optimized for animation, instead of "wait-time".
1212

13+
Example: Open a file `test/test.html` by web browser.
14+
1315
## Usage
1416

1517
Load AnimEvent into your web page.

test/test.html

+25-14
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</head>
4040
<body>
4141

42-
<div id="stage"></div>
42+
<div id="stage">Move the mouse here</div>
4343
<div class="view">
4444
<div id="bar1" class="bar"></div>
4545
<div id="count1" class="count"></div>
@@ -61,19 +61,30 @@
6161
style1 = bar1.style,
6262
style2 = bar2.style,
6363
countValue1 = 0,
64-
countValue2 = 0;
65-
66-
// Normal
67-
stage.addEventListener('mousemove', function(event) {
68-
style1.width = event.pageX + 'px';
69-
count1.textContent = ++countValue1;
70-
}, false);
71-
72-
// AnimEvent
73-
stage.addEventListener('mousemove', AnimEvent.add(function(event) {
74-
style2.width = event.pageX + 'px';
75-
count2.textContent = ++countValue2;
76-
}), false);
64+
countValue2 = 0,
65+
66+
// Normal
67+
listenerNormal = function(event) {
68+
style1.width = event.pageX + 'px';
69+
count1.textContent = ++countValue1;
70+
},
71+
// AnimEvent
72+
listenerAnimEvent = AnimEvent.add(function(event) {
73+
style2.width = event.pageX + 'px';
74+
count2.textContent = ++countValue2;
75+
});
76+
77+
stage.addEventListener('mousemove', listenerNormal, false);
78+
stage.addEventListener('mouseenter', listenerNormal, false);
79+
stage.addEventListener('mouseleave', listenerNormal, false);
80+
stage.addEventListener('mouseover', listenerNormal, false);
81+
stage.addEventListener('mouseout', listenerNormal, false);
82+
83+
stage.addEventListener('mousemove', listenerAnimEvent, false);
84+
stage.addEventListener('mouseenter', listenerAnimEvent, false);
85+
stage.addEventListener('mouseleave', listenerAnimEvent, false);
86+
stage.addEventListener('mouseover', listenerAnimEvent, false);
87+
stage.addEventListener('mouseout', listenerAnimEvent, false);
7788

7889
</script>
7990

0 commit comments

Comments
 (0)