gpt4 book ai didi

html - 使用小窗口浏览器拉伸(stretch)背景

转载 作者:行者123 更新时间:2023-12-05 06:54:50 24 4
gpt4 key购买 nike

我在一个新的 React 元素中使用 particles-js 来了解它的工作原理。我已经设置了所有内容并设法将其显示为背景,同时在页面中间放置了 React Logo 。当网页在一个小窗口中加载并且粒子被拉伸(stretch)时,问题就来了。我想我缺少 CSS 属性或其他东西,但我无法弄清楚。

你知道可能是什么错误吗?

真的谢谢你!

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="homeContainer">
<div id="particles-js">
<div id="root"></div>
</div>
</div>
<!--particles functions-->
<script type="text/javascript" src="%PUBLIC_URL%/particles.js"></script>
<!--particles config-->
<script type="text/javascript" src="%PUBLIC_URL%/utilities.js"></script>
</body>
</html>

index.css:

body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

#root {
z-index: 100;
margin: auto;
width: 100%;
height: 100%;
position: absolute;
}

canvas {
position : absolute;
width:100%;
height:100%;
z-index:-1;
}in m

这里有一些照片可以看看发生了什么:

  • 在大窗口中看起来很棒的粒子: Particles looking great in a big window
  • 加载到小窗口时粒子会拉伸(stretch) Particles stretched when loaded in a small window

更新 1:如果可能是由于 App.css 中的错误,这里是它的代码:

.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

最佳答案

你能删除 homeContainer div 吗?然后添加这些 CSS 样式:

#particles-js {
position: absolute;
width: 100%;
height: 100%;
background-color: $FFF;
background-image: url("");
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}

canvas {
display: block;
vertical-align: bottom;
}

关于html - 使用小窗口浏览器拉伸(stretch)背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65455087/

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