2 回答

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以使用標(biāo)準(zhǔn)的 javascript:window.scroll(x, y)。
前任:
window.addEventListener('load', function() {
setTimeout(function() {
window.scroll(x, y);
},1)
})
x-coord是要在左上角顯示的沿文檔水平軸的像素。
y-coord是要在左上角顯示的沿文檔垂直軸的像素。
window.addEventListener('load', function() {
setTimeout(function() {
window.scroll(screen.width/2, 0);
},1)
})
body{
background-color:0178fa;
padding:0;
text-align:center;
display: flex;
justify-content: center;
align-items: center;
overflow:auto;
}
#page {
width:100%;
height:100%;
margin:0 auto;
padding:0;
display:block;
}
#wrap-landing{
position:relative;
margin:0 auto;
padding:0;
content:url(https://i.imgur.com/gb6EyHk.png);
width:1920px;
height:1080px;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="page">
<div id="wrap-landing">
</div>
</div>
</body>
</html>

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊
數(shù)學(xué)是:
centerX = (el.scrollWidth - el.clientWidth) / 2
可滾動(dòng)#page元素的示例:
const el = (sel, par) => (par || document).querySelector(sel);
const elPage = el("#page");
const centerX = (elPage.scrollWidth - elPage.clientWidth) / 2;
const centerY = (elPage.scrollHeight - elPage.clientHeight) / 2;
elPage.scrollTo(centerX, centerY);
#page {
display: flex;
overflow: scroll;
height: 200px;
}
#image {
flex: 0 0 auto;
margin: auto;
content: url(https://i.imgur.com/gb6EyHk.png);
width: 1920px;
height: 1080px;
}
/*
PS: flex and margin:auto is used to center
#image in case is smaller than the parent.
*/
<div id="page">
<div id="image"></div>
</div>
添加回答
舉報(bào)