我有一个代码在页面右侧创建空白,因为背景比容器大,如果我想保持背景视差,我不知道如何解决这个问题。
有什么想法可以解决这个问题吗?
var lFollowX = 0,
lFollowY = 0,
x = 0,
y = 0,
friction = 1 / 60;
function moveBackground() {
x += (lFollowX - x) * friction;
y += (lFollowY - y) * friction;
translate = 'translate(' + x + 'px, ' + y + 'px) scale(1.1)';
$('#home-background').css({
'-webit-transform': translate,
'-moz-transform': translate,
'transform': translate
});
window.requestAnimationFrame(moveBackground);
}
$(window).on('mousemove click', function(e) {
var lMouseX = Math.max(-100, Math.min(100, $(window).width() / 2 - e.clientX));
var lMouseY = Math.max(-100, Math.min(100, $(window).height() / 2 - e.clientY));
lFollowX = (20 * lMouseX) / 100; // 100 : 12 = lMouxeX : lFollow
lFollowY = (10 * lMouseY) / 100;
});
moveBackground();
#home-background {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background: url("https://www.tokkoro.com/picsup/5746854-geometry-wallpapers.jpg") no-repeat center center;
background-size: cover;
z-index: -1;
}
#menu {
display: flex;
justify-content: center;
align-items: center;
background-color: #251524;
height: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section id="home">
<div id="home-background"></div>
<div id="greeting">
<h1>Hello</h1>
</div>
</section>
<section id="menu">
<ul>
<li><a href="#home">Home</a></li>
</ul>
</section>
阿波罗的战车
相关分类