我创建了一个横幅在我的主页上使用,而不是一个滑块。
它在电脑上运行得很好,甚至当我调整浏览器窗口的大小以匹配手机屏幕的宽度时。
然而,当我从一个实际的手机查看页面,背景图像是模糊的,令人难以置信的放大。不知道如何修复它,将感谢您的帮助。
function EasyPeasyParallax() {
const scrollPos = $(this).scrollTop();
// Adjusting background-position for the parallax effect
$('#custom-banner').css({
'background-position': '50% ' + (-scrollPos / 6) + "px"
});
// Adjust this function for the bannertext position
const bannerHeight = $('#custom-banner').height();
let newTop = 20 + (scrollPos * 0.1); // Adjust the factor (0.1 here) for a faster or slower parallax effect
// Make sure it doesn't move outside of the banner
if (newTop < 20) newTop = 20;
if (newTop > bannerHeight) newTop = bannerHeight;
$('#bannertext').css({
'top': newTop + '%',
'opacity': 1 - (scrollPos / 250)
});
}
$(document).ready(function() {
$(window).scroll(function() {
EasyPeasyParallax();
});
});
#custom-banner h1 {
font: 700 2.8em/1.2;
margin: 0;
color: white;
}
#custom-banner p {
color: white;
font-family: "Cormorant Infant", Sans-serif;
font-size: 24px;
font-weight: 500;
}
#custom-banner {
background: url(https://houniqueconstruction.com/wp-content/uploads/2023/09/an-awards-bg-par1.jpg) no-repeat fixed 50% 50%;
background-size: cover;
color: #fff;
height: 90vh;
width: 100%;
position: relative;
}
#bannertext {
width: 35em;
position: absolute;
/* Changed from fixed to absolute */
top: 20%;
left: 50%;
border: .5em solid #fff;
transform: translateX(-50%);
padding: 2em 0;
text-align: center;
}
/* Media Queries for smaller screens */
@media (max-width: 768px) {
#custom-banner {
height: 70vh;
}
#custom-banner h1 {
font-size: 2em;
}
#bannertext {
width: 90%;
left: 50%;
transform: translateX(-50%);
padding: 1em 0;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="custom-banner">
<div id="bannertext">
<h1>Los Angeles’ Premier Home Remodeling Contractor</h1>
<p>Finest Construction Since 1992.</p>
</div>
</div>
的数据
1条答案
按热度按时间vuktfyat1#
它可能与
background-size: cover
的解释有关,我认为您需要添加!important
,如下所示:字符串
如果成功了告诉我。