我正在使用 Javascript 代码.offset.top
来修复一个元素,但我想在到达另一个元素时结束它。
<script>
$(document).ready(function (){
var sidebartop = $('.single-content').offset().top;
$(window).scroll(function (event){
var y = $(this).scrollTop();
if ( y>= sidebartop ){
$('#sharing-links').addClass('fixed');
} else {
$('#sharing-links').removeClass('fixed');
}
});
});
</script>
这是html
<div id="sharing-links">
<!-- this is the fixed element -->
</div>
<div class="single-content">
<!-- when the div reaches here is adds the .fixed -->
<div class="div2">
<!-- I want the fixed element to end when it reaches this div -->
</div>
</div>
有谁知道如何修理它?