我有以下代码......但是当我滚动页面时它没有效果,它会在每次打开页面时生效。怎么了?它应该仅在对象从顶部保持300px时起作用。
<html>
<title>ON SCROLL TEST</title>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<link rel="stylesheet" href="http://www.justinaguilar.com/animations/css/animations.css">
<style>
#object{
background-color: #fe5652;
visibility: hidden;
}
</style>
</head>
<body>
<script>
$(window).scroll(function() {
$('#object').each(function(){
var imagePos = $(this).offset().top;
var topOfWindow = $(window).scrollTop();
if (imagePos < topOfWindow+300) {
$(this).addClass("slideUp");
}
});
});
</script>
<div style="height: 400px"></div>
<div id="object" class="slideUp" style="margin: 0 auto; width: 350px;">
TESTE <br> TESTE <br> TESTE <br> TESTE
</div>
<div style="height: 400px"></div>
</body>
</html>