gpt4 book ai didi

javascript - 加载时背景淡入

转载 作者:行者123 更新时间:2023-11-30 11:59:21 25 4
gpt4 key购买 nike

我试图让我的背景在进入网站时淡入。我尝试了几种有效的方法。但是,我只是无法将背景集中在不同的分辨率上。正如您目前在进入我的网站时看到的那样,无论何时调整浏览器大小时,背景都会始终位于中间。网址:http://studi0.ml/这正是我想要实现的目标,但仍然让地球始终处于中间位置。我的背景是纯 CSS。请记住,我刚刚开始网站设计。我已经尝试编码 2-3 周了。

html,
body {
background: url(http://studi0.ml/EzJsucI.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
-webkit-transition: background 0.0s linear;
-moz-transition: background 0.75s 0.0s linear;
-o-transition: background 0.75s 0.0s linear;
transition: background 0.75s 0.0s linear;
-moz-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
}

最佳答案

如果您希望背景图像在页面加载时淡入,我会推荐不同的设置。您可以在与页面其余部分不同的流程中拥有一个单独的 div,并在页面加载时将其设置为不透明度为 1 的动画。

HTML

<html>
<head> ... </head>
<body>
<div class="page-bg"></div>
</body>
</html>

CSS

html, body {
height: 100%;
width: 100%;
}

body {
position: relative;
}

.page-bg {
opacity: 0;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: url(http://studi0.ml/EzJsucI.jpg) no-repeat center center fixed;
background-size: cover;

animation-name: fadeIn;
animation-iteration-count: 1;
animation-timing-function: ease-in-out;
animation-duration: 1s;
animation-fill-mode:forwards;
}

@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}

当然,您可能需要为 animationkeyframes 声明添加 polyfill。 (即 -moz-animation-name-webkit-animation-name 等)

这是关于 Plunkr 的工作示例.我不得不将您使用的图片替换为带有 https 链接的图片,这样加载它就不会出现问题。

关于javascript - 加载时背景淡入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37090699/

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