[英]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>
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.