Reputation: 2755
I just want the value to increase when scrolling down and decrease when scrolling up.
This is the 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>
Here is the jQuery code:
$(window).scroll(function(){
var x=1;
x=x+1;
$("#addit").html(x);
});
As I am new to jQuery, I can't find a way for it! Can anyone help?
Upvotes: 0
Views: 1972
Reputation: 400
Please try this:
$(window).scroll(function() {
$("#addit").html($(window).scrollTop());
});
Upvotes: 2
Reputation: 6588
You don't need a variable, just:
$(window).scroll(function(){
$("#addit").html($(window).scrollTop());
});
Upvotes: 5