【发布时间】:2014-11-14 18:58:30
【问题描述】:
我正在尝试在我的网站上制作响应式视差效果。 我有这个结构:
<section id="first">
<div class="text fixed" >
<h1><b>aSs</b> lorem ipsum dolor sit amet</h1>
<p>Ogólnie znana teza głosi, iż użytkownika moze rozpraszać zrozumiała zawartośc strony, kiedy ten <span class="blue"> chce zobaczyć sam jej wygląd.</span></p>
<a class="btn btn-orange" href="#">Zobacz naszych <b>pracowników</b> ></a>
</div>
</section>
<section id="second"></section>
CSS:
#first{
background: url(../images/tlo1.jpg) no-repeat;
width: 100%;
background-size: cover;
background-position: 50%;
height: 699px;
text-align: center;
position: relative;
white-space: nowrap;
}
.fixed{
position:fixed;
top: 300px;
left: 0;
}
.static{
position: absolute;
left:0;
bottom: 0;
}
.text{
display: inline-block;
vertical-align: middle;
white-space: normal;
background: #fff;
padding: 30px 0;
width: 100%;
color: #7B7878;
font-size: 16px;
font-weight: 300;
}
Js:
pozycjaBlueBox = $("#first").offset().top + $('#first').height();
$(document).scroll(function(){
if($(window).width() <=1024){
pozycjaScrolla = $(window).scrollTop() + $("#first .text").offset().top+$("#first .text").height();
}else{
pozycjaScrolla = $(window).scrollTop() + $("#first .text").offset().top-60;
}
if($(window).width() > 768){
if(pozycjaScrolla >= pozycjaBlueBox){
$("#first .text").removeClass('fixed').addClass('static');
}else{
$("#first .text").removeClass('static').addClass('fixed');
}
}
});
我想要固定文本类,直到该类的底部不与#second 的顶部接触。它在大型桌面上运行良好,但是当我调整到较低的分辨率时,它就变得一团糟了。
【问题讨论】:
-
我们无法用这么少的资源重现您的示例。你就不能摆弄一下吗?
-
当然:jsfiddle.net/ohjhzkfb 这是全屏及其工作原理:jsfiddle.net/ohjhzkfb/embedded/result
-
有什么问题?
-
将窗口大小调整为小分辨率,然后此脚本将不起作用。我想对宽度 > 768 的所有分辨率都有这种视差效果。
标签: javascript jquery css html parallax