In the scroll() event of jquery, I want to determine whether the current scroll bar is horizontal or vertical;
I started to use global variables to record the value of scrollTop to judge. If the front and rear values do not change, it means horizontal scrolling,
But if there are multiple scroll bars on the page, multiple global variables are needed to control them. How to judge?
scroll jquery distinguishes between horizontal and vertical scroll bars
Solution:
Just set the scrollLeft/scrollTop of the selected object in the selector once each, and then bind the scroll event. When triggered, get the scrollLeft/scrollTop and compare it with the initialized scrollLeft/scrollTop to determine whether it is horizontal or vertical. At the same time Update scrollLeft/scrollTop of object storage
<script><br>$('div').each(function(){$(this).data('slt',{sl:this.scrollLeft,st:this.scrollTop});} ).scroll(function(){<br> var sl=this.scrollLeft,st=this.scrollTop,d=$(this).data('slt');<br> if(sl!=d.sl) alert('horizontal scroll');<br> if(st!=d.st)alert('vertical scroll');<br> $(this).data('slt',{sl:sl,st:st });///<br>})<br></script>