我正在試驗視差並試圖在滾動上獲得一個很好的縮小,但我正在努力與圖像變得比瀏覽器寬度和div
的高度更小。視差縮小效果問題
正如你在我的例子中看到的那樣,當你向下滾動時,包裝部分的紅色背景是可見的。
您可以查看例如在www.adamkhourydesign.com/test
HTML
<header id="header_container">
<div class="header_back"></div>
<div class="logo"></div>
</header>
CSS
#header_container {
position: relative;
height: 600px;
background-color: rgba(255, 100, 85, 0.5);
background-repeat: no-repeat;
background-size: auto 800px;
background-position: top center;
background-attachment: fixed;
overflow: hidden;
}
.logo {
height: 100px;
width: 100%;
background-image: url(../img/name.png);
background-position: center;
background-repeat: no-repeat;
position: absolute;
top: 50%;
margin-top: -50px;
}
.header_back {
position: relative;
height: 600px;
background-repeat: no-repeat;
background-size: cover;
background-position: top center;
background-attachment: fixed;
background-image: url(../img/header_bg.jpg);
overflow: hidden;
}
jQuery的
var pContainerHeight = $('#header_container').height();
$(window).scroll(function(){
var wScroll = $(this).scrollTop();
var wZoomIn = 1+(wScroll*.0005);
var wZoomOut = 1-(wScroll*.00005);
if (wScroll <= pContainerHeight) {
$('.header_back').css({
'transform' : 'scale('+ wZoomOut +')'
});
$('.logo').css({
'transform' : 'translate(0px, '+ wScroll /0.7 +'%)'
});
}
您設置了'transform:scale()',所以顯然它會縮放,使其變小。 – GolezTrol