Javascript jQuery在滚动时增加和减少值

Javascript jQuery在滚动时增加和减少值,javascript,jquery,Javascript,Jquery,我只希望向下滚动时该值增加,向上滚动时该值减少 这是HTML: <html> <head> <script src="/jquery.min.js"></script> <script src="9.js"></script> <style> #addit { position:fixed; top:0px; left:0px; } </style> </head> <body&g

我只希望向下滚动时该值增加,向上滚动时该值减少

这是HTML:

<html>
<head>
<script src="/jquery.min.js"></script>
<script src="9.js"></script>
<style>
#addit
{
position:fixed;
top:0px;
left:0px;
}
</style>
</head>

<body>
<div id="addit">
</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br>
</body>
</html>
因为我是jQuery新手,所以我找不到方法!
有人能帮忙吗?

您不需要变量,只要:

$(window).scroll(function(){
    $("#addit").html($(window).scrollTop());
});
请尝试以下方法:

$(window).scroll(function() {
    $("#addit").html($(window).scrollTop());
});
这里已经有答案了
$(window).scroll(function() {
    $("#addit").html($(window).scrollTop());
});