如何在将数据加载到Post
后阻止ThreadsContainer
容器跳转?我希望它保持固定在顶部。
$('.Loadthreads').on("click",function () {
$('.threatsContainer').append("<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem");
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="threatsContainer"></div>
<div class="Loadthreads" style="cursor:pointer;">[Load Threads]</a>
<div class="Post" style="background:red;">[I want to maintain fixed at the top after the data above has loaded]</div>
&#13;
我在考虑使用scroll:overflow,visble
,但没有...我不想使用固定位置。
答案 0 :(得分:1)
$('.Loadthreads').on("click",function () {
$('.threatsContainer').append("<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem<br>lorem");
$('html, body').animate({scrollTop: $(".Post").offset().top}, 0);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="wrapper">
<div class="threatsContainer"></div>
<div class="Loadthreads" style="cursor:pointer;">[Load Threads]</a>
<div class="Post" style="background:red;">[I want to maintain fixed at the top after the data above has loaded]</div>
</div>
你可以做的是使用jQuery加载上面的数据后滚动到.Post div。希望能帮到你。