简体   繁体   English

如何从中心而不是顶部准备/启动页面?

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

相关问题 如何从 0 而不是从顶部开始获取 d3.js 条形图 - How can I get the d3.js bar chart start from 0 instead of from the top 而不是准备好的数据,我如何从csv中读取? - instead of ready data how can i read from csv? 我如何才能使此计时器从点击开始而不是在页面加载开始? - How can i get this timer to start on click instead of on page load? 我怎样才能在PhantomJS中等待页面准备好? - How can I wait for the page to be ready in PhantomJS? 我怎样才能让这个类似苹果的图像序列 animation 在网站中间开始,而不是只在顶部? - How can I get this Apple-like image sequence animation to start in the middle of the website, instead of only on top? 如何在中心而不是顶部开始滚动(溢出-y:滚动)div? - How to start scrollable (overflow-y: scroll) div in the center instead of the top with scrolling? $ {document).ready不能替换在页面底部声明的js,但是我需要在脚本顶部 - $(document).ready can't replace js declared at bottom of the page, but I need to have the script at the top 我如何防止链接将我发送到页面顶部 - How can i prevent from link to send me to the top of the page 我怎样才能做到只加载选项卡区域而不是单击选项卡后页面跳转到顶部? - How can I make it so only the tab area loads instead of the page jumping to the top after clicking on tab? 当我从顶部滚动时如何暂停转盘/滑块,然后再滚动至顶部时又重新开始? - How can I pause carousel/slider when I scroll from top and start again when I scroll to top?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM