我无法触发两个事件——一个在一个滚动位置,一个在另一个。
正如您将在下面看到的,我试图div
#one
在用户到达时出现300px
,而div
#two
在之后出现600px
。
CSS:
<style type='text/css'>
body {
height:5000px;
}
#base {
position:fixed;
width:300px;
height:250px;
margin-left:100px;
margin-top:0;
background-color:blue;
z-index:1;
}
.feature {
position:fixed;
width:300px;
height:250px;
margin-left:100px;
}
#one {
margin-top:250px;
background-color:red;
z-index:2;
}
#two {
margin-top:500px;
background-color:yellow;
z-index:3;
}
</style>
JS:
<script type='text/javascript'>
$(window).load(function(){
$(document).ready(function(){
$(document).scroll(function() {
var top = $(document).scrollTop();
if (top > 300) {
$('#one').show();
}
else if (top > 600) {
$('#two').show();
}
else {
$('.feature').hide();
}
});
});
});
</script>
HTML:
<body>
<div id="base"></div>
<div id="one" class="feature"></div>
<div id="two" class="feature"></div>
</body>