0
我刚刚注意到当我滚动到我的几个网页的底部时,滚动回到顶部,并且回到底部同样,背景应该在底部出现一个大的空白区域。我查看了其他几个解决方案,例如:Random white space at bottom of page but only on mobile,但该解决方案似乎无法解决问题。我无法通过选择移动设备来使用Chrome开发人员工具复制该问题,因此我无法排除代码中可能导致此行为的错误。下面是其中一个页面的相关代码:滚动到底部并备份后,出现在页面底部的空白(手机)
function offset(elementToOffsetBy, elementToOffset, minScreenSize) {
\t var width = $(window).width();
\t if(width >= minScreenSize) {
\t \t var x = document.getElementById(elementToOffsetBy);
\t \t var height = x.offsetHeight;
\t \t var top_offset = height * -1;
\t \t document.getElementById(elementToOffset).style.top = top_offset + "px";
\t \t document.getElementById(elementToOffset).style.bottom = "0px";
\t }
}
body, html {
\t height: 100%;
}
#portfolio {
\t background: url("https://ndmikkiholicdotcom.files.wordpress.com/2016/06/black-and-white-brick-wall-background-white-brick-wall-image-decoration-picture-white-brick-wall.jpg") no-repeat center center fixed;
\t background-size: cover;
}
.topnav {
\t overflow: hidden;
}
.topnav a.selected {
\t background-color: rgba(242, 242, 242, .3);
\t color: #3b4e6b;
}
.topnav a {
\t float: left;
\t display: block;
\t color: #f2f2f2;
\t text-align: center;
\t text-decoration: none;
\t font-size: 20px;
\t padding: 20px 25px;
}
.topnav a:hover {
\t color: #3b4e6b;
\t background-color: rgba(242, 242, 242, .3);
}
.topnav .icon {
\t /* Hide icon to expand menu */
\t display: none;
}
/* When screen is less than 600px wide, hide all links except the first one, and display the icon to expand the menu */
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
/* When screen is less than 600px wide, display all links vertically when icon is clicked */
@media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
\t color: #f2f2f2;
\t background-color: #3b4e6b;
}
.topnav.responsive a:hover {
\t color: #3b4e6b;
\t background-color: #f2f2f2;
}
}
.portfolio_img {
\t width: 80%;
\t height: 80%;
\t margin-left: 4em;
\t margin-right: 4em;
\t margin-bottom: 3em;
\t margin-top: 3em;
}
.hover_img {
\t display: inline-block;
\t width: 100%;
\t height: 100%;
}
.hover_img:hover img {
\t opacity: .2;
}
.hover_img:hover .center_text {
\t display: block;
}
.center_text {
\t position: absolute;
\t top: 50%;
\t left: 50%;
\t transform: translate(-50%, -50%);
\t display: none;
\t font-weight: bold;
}
.col-md-4 {
\t position: relative;
\t text-align: center;
}
.row {
\t display: flex;
\t display: -webkit-flex;
\t flex-wrap: wrap;
}
<!DOCTYPE html>
<html>
\t <head>
\t \t <title>Portfolio</title>
\t \t <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
\t \t \t rel="stylesheet">
\t \t <link href="styles.css" rel="stylesheet" type="text/css">
\t \t <link href="image_styles.css" rel="stylesheet" type="text/css">
\t \t <link rel='shortcut icon' type='image/x-icon' href='logo.ico'/>
\t \t <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" \t ></script>
\t \t <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
\t \t <script src="navbar.js"></script>
\t </head>
\t
\t <body id="portfolio">
\t \t <div class="topnav" id="myTopnav">
\t \t \t <a href="index.html">Home</a>
\t \t \t <a href="about.html">About</a>
\t \t \t <a href="#" class="selected">Portfolio</a>
\t \t \t <a href="contact.html">Contact</a>
\t \t \t <a class="icon" onclick="myFunction()">☰</a>
\t \t </div>
\t \t
\t \t <div class="container">
\t \t \t <h1><b>Projects</b></h1>
\t \t \t <div class="row">
\t \t \t \t <div class="col-md-4">
\t \t \t \t \t <div class="hover_img">
\t \t \t \t \t \t <img class="portfolio_img" src="https://pixy.org/images/placeholder.png" alt="Breakout">
\t \t \t \t \t \t <div class="center_text"><a href="https://github.com/" target="_blank">Breakout</a>.</div>
\t \t \t \t \t </div>
\t \t \t \t </div>
\t \t \t </div>
\t \t \t
\t \t \t <h1><b>Websites</b></h1>
\t \t \t <div class="row">
\t \t \t \t <div class="col-md-4">
\t \t \t \t \t <div class="hover_img">
\t \t \t \t \t \t <img class="portfolio_img" src="https://pixy.org/images/placeholder.png" alt="Flashcard App">
\t \t \t \t \t \t <div class="center_text"><a href="https://pixy.org/images/placeholder.png" target="_blank">Chemistry Flashcard Web App</a></div>
\t \t \t \t \t </div>
\t \t \t \t </div>
\t \t \t \t
\t \t \t \t <div class="col-md-4">
\t \t \t \t \t <div class="hover_img">
\t \t \t \t \t \t <img class="portfolio_img" src="https://pixy.org/images/placeholder.png">
\t \t \t \t \t \t <div class="center_text"><a href="https://pixy.org/images/placeholder.png" target="_blank">Personal Website</a></div>
\t \t \t \t \t </div>
\t \t \t \t </div>
\t \t \t \t
\t \t \t \t <div class="col-md-4">
\t \t \t \t \t <div class="hover_img">
\t \t \t \t \t \t <img class="portfolio_img" src="https://pixy.org/images/placeholder.png">
\t \t \t \t \t \t <div class="center_text"><a href="https://pixy.org/images/placeholder.png" target="_blank">Website</a></div>
\t \t \t \t \t </div>
\t \t \t \t </div>
\t \t \t </div>
\t \t \t <h1><b>Publications</b></h1>
\t \t \t <div class="row">
\t \t \t \t <div class="col-md-4">
\t \t \t \t \t <div class="hover_img">
\t \t \t \t \t \t <img class="portfolio_img" src="https://pixy.org/images/placeholder.png">
\t \t \t \t \t \t <div class="center_text">Author of <a href="https://www.arcadiapublishing.com/" target="_blank">Book</a></div>
\t \t \t \t \t </div>
\t \t \t \t </div>
\t \t \t \t
\t \t \t \t <div class="col-md-4">
\t \t \t \t \t <div class="hover_img">
\t \t \t \t \t \t <img class="portfolio_img" src="https://pixy.org/images/placeholder.png" alt="Red Alert Politics">
\t \t \t \t \t \t <div class="center_text"><a href="http://redalertpolitics.com" target="_blank">Red Alert Politics</a></div>
\t \t \t \t \t </div>
\t \t \t \t </div>
\t \t \t \t
\t \t \t \t <div class="col-md-4">
\t \t \t \t \t <div class="hover_img">
\t \t \t \t \t \t <img class="portfolio_img" src="https://pixy.org/images/placeholder.png">
\t \t \t \t \t \t <div class="center_text"><a href="https://www.loneconservative.com" target="_blank">Lone Conservative<a/></div>
\t \t \t \t \t </div>
\t \t \t \t </div>
\t \t \t </div>
\t \t </div>
\t </body>
</html>
可能是相对于https://stackoverflow.com/questions/24944925/background-image-jumps-when-address-bar-hides-ios-android-mobile-chrome –