加载后如何在中心中心或特定高度开始页面
How to start page at center of center or at specific height after load
我想在水平和垂直的中心开始页面,当它已经加载(不是在顶部),有人有什么建议吗?或者在一个特定的高度,如果可能的话。谢谢你!
你可以这样做:
$(document).ready(function() {
$(window).scrollTop($(window).height()/2);
$(window).scrollLeft($(window).width()/2);
});
你可以根据自己的需要改变位置。
也可以使用$(window).scrollTo($(window).width()/2, $(window).height()/2);
不知道你在问什么,但你试过相对坐标吗?
like>>
/*i put this all css selector for canceling all margins, paddings so i can remove default browser prefereces for the same*/
/*border box is just that any size od div is not changed after addinational padding*/
*{margin:0;padding:0;box-sizing:border-box;}
body{
position:absolute;
width:100%;height:100%;
background-color:red;
padding-top:10%;
padding-left:10%;
padding-right:10%;
padding-bottom:10%;
}
centerd{
/*relative dimensions wont work if not display:block;*/
display:block;
width:100%;height:100%;
background-color:blue;
}
<!doctype html>
<html>
<meta charset = "UTF-8" />
<title>Center Content</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<body>
<centerd>
<!--html5 element, you can create your own -->
</centerd>
</body>
</html>
更多信息请访问:这是一个很酷的方式来了解足够的html, css, javascript等
虽然不确定这是否是您正在寻找的:
要使容器(例如DIV元素)水平居中,在CSS中设置固定宽度和自动左右距:
div#container
{ width: 1024px; /* a fixed width container */
border: thin solid green; /* debug, to see */
margin-left: auto;
margin-right: auto;
}
然后是一个匿名JavaScript函数,在加载后使用它的margin-top属性将容器垂直居中:
function ()
{ var e = document.getElementById("container");
var eHeight = e.offsetHeight;
var clientHeight = document.documentElement.clientHeight;
var marginTop = 0;
if(clientHeight > eHeight)
{ marginTop = (clientHeight - eHeight) >> 1; // integer divide by 2
}
e.style.marginTop = marginTop + "px";
}
使用jQuery的ready()函数将添加到页面的窗口,以及HTML
<div id="container">
hello this is page content
</div>
将容器元素居中
老问题,但我只是使用:
function Scrolldown() {
window.scroll(250, 400);
}
window.onload = Scrolldown;
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- ExtJS——在展开/折叠时调整面板高度
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 单击页面上的链接后高度发生变化
- 不加载宽度和高度的角度pintura
- 查找元素高度,包括边距
- 如何自动调整标签的高度以适应内容
- Javascript高度问题
- 使用JavaScript根据窗口/视口的高度动态调整图像大小
- 如何添加类,同时开始在文本字段中输入文本
- 如何计算每个元素's的高度,并将这些值用作函数中的变量
- 如果宽度是百分比,如何设置以px为单位的图像高度
- 通过jquery设置最小高度
- 文档就绪提供了错误的选择器高度
- 希望日期开始结束于while循环中的一个房间id的一个数组
- 调整缩放窗口高度提升缩放
- 更新画布上的高度/宽度并重新开始绘制
- CSS关键帧——从动态高度开始
- 在动画开始时改变元素高度(Angular)
- 加载后如何在中心中心或特定高度开始页面