我在背景图像上有一个h1,
<section class="cd-intro">
<h1>Content</h1>
</section>`使用以下css:
.cd-intro {
position: relative;
height: 100%;
background: url("../img/buff.jpg") no-repeat center center;
background-size: cover;
z-index: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}我希望能或多或少准确地复制这里的效果,尽可能简洁。投入感谢。
发布于 2015-06-06 21:22:36
关于基本视差效应在此之前的问题已经被问到了,所以如果你还在想这个问题的话,看看堆叠溢出吧。
关于视差标头运动,简短的回答是:
jQuery(window).scroll(function() {
//Get the scoll position of the page
scrollPos = jQuery(this).scrollTop();
//Scroll and fade out the banner text
jQuery('.featured-title').css({
'margin-top' : -(scrollPos/3)+"px",
'opacity' : 1-(scrollPos/300)
});
});我是通过查看网站上的javascript源来实现这一目标的。您将在main.js中看到
///////////////////////////////
// Parallax Scrolling
///////////////////////////////
// Calcualte the home banner parallax scrolling
function scrollBanner() {
//Get the scoll position of the page
scrollPos = jQuery(this).scrollTop();
//Scroll and fade out the banner text
jQuery('.featured-title').css({
'margin-top' : -(scrollPos/3)+"px",
'opacity' : 1-(scrollPos/300)
});
}
jQuery(document).ready(function(){
///////////////////////////////
// Initialize Parallax
///////////////////////////////
if(!isMobile()) {
jQuery(window).scroll(function() {
scrollBanner();
});
}
else {
jQuery('#banner-text').css({
'position': 'relative',
'text-align': 'center',
'margin': 'auto',
'padding': '0',
'top':'0'
});
}
/* bunch of other stuff */
}这里所做的是监听scroll对象上的window事件。当此事件触发时,margin-top值和opacity将与滚动的距离成比例地更改(参见scrollBanner函数)。
https://stackoverflow.com/questions/30687360
复制相似问题