<table class="javascript">
<tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
@H_4041@</td>
<td class="de1"><pre class="de1">scroll<span class="br0">(<span class="kw1">function<span class="br0">(direction<span class="br0">) <span class="br0">{ console.<span class="me1">log<span class="br0">(direction<span class="br0">) <span class="br0">}<span class="br0">)<span class="sy0">;
<span class="kw1">function scroll<span class="br0">( fn <span class="br0">) <span class="br0">{
<span class="kw1">var beforeScrollTop <span class="sy0">= document.<span class="me1">body.<span class="me1">scrollTop<span class="sy0">,
fn <span class="sy0">= fn <span class="sy0">|| <span class="kw1">function<span class="br0">(<span class="br0">) <span class="br0">{<span class="br0">}<span class="sy0">;
window.<span class="me1">addEventListener<span class="br0">(<span class="st0">"scroll"<span class="sy0">, <span class="kw1">function<span class="br0">(<span class="br0">) <span class="br0">{
<span class="kw1">var afterScrollTop <span class="sy0">= document.<span class="me1">body.<span class="me1">scrollTop<span class="sy0">,
delta <span class="sy0">= afterScrollTop <span class="sy0">- beforeScrollTop<span class="sy0">;
<span class="kw1">if<span class="br0">( delta <span class="sy0">=== <span class="nu0">0 <span class="br0">) <span class="kw1">return <span class="kw2">false<span class="sy0">;
fn<span class="br0">( delta <span class="sy0">> <span class="nu0">0 <span class="sy0">? <span class="st0">"down" <span class="sy0">: <span class="st0">"up" <span class="br0">)<span class="sy0">;
beforeScrollTop <span class="sy0">= afterScrollTop<span class="sy0">;
<span class="br0">}<span class="sy0">, <span class="kw2">false<span class="br0">)<span class="sy0">;
<span class="br0">}
@H404_1@</td>
</tr></table> 原文链接:https://www.f2er.com/note/421979.html