gpt4 book ai didi

javascript - jQuery - 屏幕调整大小更新

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:27 25 4
gpt4 key购买 nike

如何在调整屏幕大小(缩放)时更新屏幕高度?每次缩放屏幕时,箭头都会断掉。

另外我想问你,我在屏幕上显示图像的方式是否是一个好方法......它应该被制作成一个视差网站,每次向下滚动时,它应该换成另一个尖锐的 (#) 并滚动到不同的内容,这些内容将按原样放在下面。当你点击箭头时移动并不是很流畅,它只是改变了,但不是很流畅,我猜这是一个问题......

这是我的代码:

    /* Resize to fit screen */
window.onload = function() {
var height = getViewportHeight();
document.getElementById("main").style.height = height + "px";
document.getElementById("lobby").style.height = height + "px";
}

function getViewportHeight() {
var h = 0;
if(self.innerHeight)
h = window.innerHeight;
else if(document.documentElement && document.documentElement.clientHeight)
h = document.documentElement.clientHeight;
else if(document.body)
h = document.body.clientHeight;
return h;
}

HTML:

<!DOCTYPE html>
<html lang="cs">
<head>
<title>Zahrajem.cz | Nový československý herní portál</title>
<meta charset="utf-8">
<meta name="author" content="Jan Dvořák">
<meta name="description" content="Zahrajem.cz | Nový český herní portál">
<meta name="version" content="1.0">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,700">
<script src="http://code.jquery.com/jquery-2.2.2.min.js"></script>
<script src="main.js"></script>
</head>
<body>
<section id="main">
<div class="container">
<div class="header">
<img src="img/z_logo.png"/>
</div>

<div class="footer">
<a href="#lobby"><img src="img/z_down.png"/></a>
</div>
</div>
</section>

<section id="lobby">
<div class="container">
<div class="header">
<a href="#main"><img src="img/z_up.png"/></a>
</div>
</div>
</section>
</body>
</html>

CSS:

html, body {
font-family: "Open Sans", "sans-serif";
}

* {
padding: 0;
margin: 0;
}



/* ANIMATION */
@-webkit-keyframes pulsate {
0% {-webkit-transform: scale(0.92, 0.92);}
100% {-webkit-transform: scale(1.0, 1.0);}
}
@-moz-keyframes pulsate {
0% {-webkit-transform: scale(0.92, 0.92);}
100% {-webkit-transform: scale(1.0, 1.0);}
}
@keyframes pulsate {
0% {-webkit-transform: scale(0.92, 0.92);}
100% {-webkit-transform: scale(1.0, 1.0);}
}

@-webkit-keyframes arr {
0% {opacity: 0.4;}
100% {opacity: 1.0;}
}
@-moz-keyframes arr {
0% {opacity: 0.4;}
100% {opacity: 1.0;}
}
@keyframes arr {
0% {opacity: 0.4;}
100% {opacity: 1.0;}
}



/* STRUCTURE */
#main {
overflow: auto;
background-image: url('/img/z_background.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
display: block;
}

#main .container {
margin: auto;
text-align: center;
}

#main .container .header {
margin-top: 10%;
}

#main .container .header img {
-webkit-animation: pulsate 2s ease-in-out infinite alternate;
-moz-animation: pulsate 2s ease-in-out infinite alternate;
animation: pulsate 2s ease-in-out infinite alternate;
}

#main .container .footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}

#main .container .footer img {
width: 50px;
height: 50px;
opacity: 0.4;
}
#main .container .footer img:hover {
-webkit-animation: arr 0.7s ease-out infinite alternate;
-moz-animation: arr 0.7s ease-out infinite alternate;
animation: arr 0.7s ease-out infinite alternate;
}

/* LOBBY */

#lobby {
overflow: auto;
background-image: url('/img/z_lobby_bg.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
display: block;
}

#lobby .container {
margin: auto;
text-align: center;
}

#lobby .container .header {
position: absolute;
left: 0;
right: 0;
}

#lobby .container .header img {
width: 50px;
height: 50px;
opacity: 0.4;
}
#lobby .container .header img:hover {
-webkit-animation: arr 0.7s ease-out infinite alternate;
-moz-animation: arr 0.7s ease-out infinite alternate;
animation: arr 0.7s ease-out infinite alternate;
}

如果您发现有问题或可以用更好的方式进行改进,请随时更正我当前的代码。我想会有很多错误,所以我请你帮我改正我的错误并帮助我一点。

预览:http://zahrajem.cz/

最佳答案

就像 onload 一样,我们有一个 onresize 事件:

window.onresize = function(event) {
var height = getViewportHeight();
document.getElementById("main").style.height = height + "px";
document.getElementById("lobby").style.height = height + "px";
};

关于javascript - jQuery - 屏幕调整大小更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36249564/

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