gpt4 book ai didi

javascript - 垂直和水平居中以及javascript滚动的问题

转载 作者:行者123 更新时间:2023-11-28 05:45:02 28 4
gpt4 key购买 nike

我有一个网站,我希望其中有一张以 100% 宽度和 100% 高度显示的图片,上面有一个按钮,可以将页面滚动到窗口的高度。我希望这个按钮垂直和水平居中,但我尝试的所有方法都不起作用,而且我似乎也无法让它滚动。我将为任一问题提供答案。 https://jsfiddle.net/cityFoeS/278dcyqg/

<!DOCTYPE html>
<html>
<head>
<style>
html, body {
height: 100%;
width: 100%;
background: -webkit-linear-gradient(left top, black, #404040); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(bottom right, black, #404040); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(bottom right, black, #404040); /* For Firefox 3.6 to 15 */
background: linear-gradient(to bottom right, black, #404040); /*Standard syntax (must be last) */
background-repeat: no-repeat;
background-attachment: fixed;
}

#start {
color: white;
background: url('http://www.wallpaperup.com/uploads/wallpapers/2013/05/16/86283/a5d366f61be34ae146c3acc00e288ade.jpg') no-repeat center center fixed;
height:100%;
width: 100%;
padding:20px;
box-sizing: border-box;
}
#reading {
height: 100%;
width: 100%;
}
</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
function scrollWin() {
var h = window.innerHeight;
window.scrollTo(0, h);
}
</script>
</head>
<link href='https://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
<body>
<div id="start"><button id="start-reading"onclick="myFunction()">Start Reading</button></div>
<div id="reading"></div>
</body></html>

最佳答案

您的问题出在 HTML 中,<div id="start"><button id="start-reading"onclick="myFunction()">Start Reading</button></div>

看看onclick部分,您正在调用一个不存在的函数。

您只需将其更改为正确的函数名称即可,它会起作用,但我却采用了最佳实践: https://jsfiddle.net/278dcyqg/1/

您应该尝试避免使用 onclick在实际的 HTML 标签上,并尝试通过 JavaScript 处理所有事件

关于javascript - 垂直和水平居中以及javascript滚动的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38597761/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com