如何实现.preloader div下滑隐藏且不产生页面滚动条及底部多余留白
解决方案
修改以下几处即可同时实现2秒延时启动、下滑隐藏、无滚动条无留白的效果:
- 给html、body加横向溢出隐藏规则,避免元素位移触发滚动条
- 调整preloader动画参数,增加2秒启动延时,动画结束后隐藏元素避免占用空间
- 移除原HTML中多余的闭合标签,避免布局异常
修改后的代码
CSS部分
* { margin: 0; padding: 0; box-sizing: border-box; } /* 新增规则,避免溢出滚动 */ html, body { overflow-x: hidden; } body { font-family: "Poppins", sans-serif; min-height: 100vh; display: flex; align-items: center; justify-content: center; perspective: 1000px; background-image: url('background_image_one.jpg'); background-repeat: no-repeat; background-attachment: fixed; background-size: cover; background-position: center; } .container { width: 50%; display: flex; justify-content: center; align-items: center; } .card { transform-style: preserve-3d; background-color: rgba(0, 0, 0, 0.5); border: white; border-style: solid; min-height: 60vh; width: 35rem; border-radius: 30px; padding: 0rem 5rem; box-shadow: 0 20px 20px rgba(0, 0, 0, 0.2), 0px 0px 50px rgba(0, 0, 0, 0.2); } .avatar { min-height: 35vh; display: flex; align-items: center; justify-content: center; } .avatarimg { width: 40rem; z-index: 2; transition: all 0.75s ease-out; } .info h1 { font-size: 3rem; transition: all 0.75s ease-out; display: flex; justify-content: center; color: white; } .info h3 { font-size: 1.3rem; padding: 2rem 0rem; color: #585858; font-weight: lighter; transition: all 0.75s ease-out; } .sizes { display: flex; justify-content: space-evenly; transition: 0.5s ease-out; padding-bottom: 2rem; } .sizes button { box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2); cursor: pointer; font-weight: bold; width: 100%; padding: 1rem 0rem ; background: #f54642; border: none; color: white; border-radius: 30px; font-weight: bolder; margin: 1rem; } button.active { background: #585858; color: white; } .purchase { margin-top: 5rem; transition: all 0.75s ease-out; } input[type="text"], input[type="password"] { border: none; border-bottom: 0px; background: rgba(255, 255, 255, 0.2); color: whitesmoke; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; outline: none; height: 40px; width: 100%; font-size: 16px; transition: all 0.75s ease-out; } .forminput p { font-size: 18px; color: white; } .forminput { padding-bottom: 3rem; } .preloader { background: #000823 url("bold-preloader.gif") no-repeat center center; min-height: 100vh; height: 100vh; width: 100%; position: fixed; top: 0; left: 0; z-index: 100; /* 调整动画:动画时长1秒,2秒后启动,保持结束状态,可自行修改第一个参数调整动画速度 */ animation: slide 1s ease-out 2s forwards; } @keyframes slide{ 0% { transform: translateY(0); visibility: visible; } 100%{ transform: translateY(100vh); visibility: hidden; pointer-events: none; } }
HTML部分
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>3d Card Effect</title> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500&display=swap" rel="stylesheet"> <link rel="stylesheet" href="./style.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> </head> <body> <div class="preloader"> </div> <div class="container"> <div class="card"> <div class="avatar"> <div class="circle"></div> <img src="./userAvatar.png" alt="avatarimg" class="avatarimg"> </div> <div class="info"> <h1 class="title">Log In</h1> <div class="forminput"> <p>Email:</p> <input type="text" name="" placeholder=""> <p>Password:</p> <input type="password" name="" placeholder=""> </div> </div> <div class="sizes"> <button>Login</button> <button>Register</button> </div> </div> </div> <script src="./app.js"></script> </body> </html>
内容的提问来源于stack exchange,提问作者user14764548
相关产品推荐
相关产品推荐

