我正在写一些jquery,我有一个变量,其值根据滚动而增加和减少。我只想知道它的价值在何时增加或减少。意味着当滚动发生时检查它的值是增加还是减少。 谢谢
答案 0 :(得分:0)
您可以尝试在jquery的滚动事件上检查变量值。
x = 0;
$(document).ready(function(){
$("div").scroll(function(){
$("span").text( x+= 1);
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>Try the scrollbar in the div</p>
<div style="border:1px solid black;width:200px;height:100px;overflow:scroll;">In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since.
<br><br>
'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.'
</div>
<p>Scrolled <span>0</span> times.</p>
</body>
</html>