简体   繁体   English

防止div在其上加载数据后跳下

[英]Prevent div jumps down after loading data above it Jquery

How do I prevent the Post container jumps down after loading data into ThreadsContainer ? 在将数据加载到ThreadsContainer后,如何防止Post容器跳下来? I want it to maintain fixed to the top. 我希望它保持在顶部。

  $('.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"); }); 
 <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> 
This technique is used on Twitter, when you visit the page of a comment of a thread. 当您访问主题注释页面时,在Twitter上使用了此技术。 the comment remains steady up, while the threads load above it. 注释保持稳定,而线程在其上方加载。 without moving it. 不动它。

I was thinking using scroll:overflow,visble but nothing...I dont want to use fixed positionning. 我在想使用scroll:overflow,visble但什么也没有...我不想使用固定位置。

  $('.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> 

What you can do is scroll to the .Post div after loading the data above it using jQuery. 您可以做的是在使用jQuery加载上方的数据后,滚动到.Post div。 Hope will help you. 希望会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM