<html>
<body>
<div style="height: 5000px; width: 10px;"></div>
<div style="position: fixed; left: 50px; top: 50px; height: 50px; width: 50px; background-color: red;"></div>
</body>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
var div = $('div:last');
$(window).scroll(function(){
var top = $(this).scrollTop();
console.log(top);
if (top > 1800 && top < 3000) {
div.css('background-color', 'green');
} else {
div.css('background-color', 'red');
}
});
</script>
</html>
можно так:
var div = $('div:last');
$(window).scroll(function(){
var top = $(this).scrollTop();
console.log(top);
div.css('background-color', (top > 1800 && top < 3000) ? 'green': 'red');
})
|