[英]How can I ready/start the page from the center instead of top?
i would like to do some animation in my website main page, when it's open/ready, to start from the center of the page then goes up smoothly to the top in JavaScript or HTML or CSS?我想在我的网站主页上做一些 animation,当它打开/准备好时,从页面中心开始,然后顺利上升到 JavaScript 或 HTML 或 CSS 的顶部? (i'm looking for the easiest simplest way)
(我正在寻找最简单的方法)
I made a small example for you using scrollIntoView ()
, on jquery
.我在 jquery 上使用
jquery
scrollIntoView ()
为你做了一个小例子。 Also, set setTimeout()
to delay before scrolling to the top of the page.此外,将
setTimeout()
设置为在滚动到页面顶部之前延迟。
This is not a perfect solution, as I did it with a hastily:) But you can improve my solution.这不是一个完美的解决方案,因为我仓促地完成了:)但是你可以改进我的解决方案。
$(window).on('load', function() { $("body")[0].scrollIntoView({ block: "center" }); setTimeout(function(){ $("html, body").animate({ scrollTop: 0 }, 1000) }, 3000); });
.main { display: flex; flex-direction: column; }.header { height: 100px; background-color: green; }.content { height: 3000px; background-color: yellow; }.footer { height: 100px; background-color: red; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="main"> <div class="header"> </div> <div class="content"> </div> <div class="footer"> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.