87,907
社区成员
发帖
与我相关
我的任务
分享
window.onload=function(){
var o=document.getElementById('div1');
o.setAttribute('osl',o.scrollLeft)
o.setAttribute('ost',o.scrollTop);
o.onscroll=function(){
var sl=this.scrollLeft,
st=this.scrollTop,
ost=this.getAttribute('ost'),
osl=this.getAttribute('osl');
if(sl!=osl)alert('水平滚动');
if(st!=ost)alert('垂直滚动');
this.setAttribute('ost',st);
this.setAttribute('osl',sl);
}
}
<div style="width:200px;height:200px;overflow:auto" id="div1">
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1
</div>
<script type="text/javascript">
window.onload=function(){
document.getElementById('div1').onscroll=function(){
var sl=this.scrollLeft,st=this.scrollTop
,ost=this.getAttribute('ost'),osl=this.getAttribute('osl');
if(sl!=osl)alert('水平滚动');
if(st!=ost)alert('垂直滚动');
this.setAttribute('ost',st);
this.setAttribute('osl',sl);
}
}
</script>