简体   繁体   English

Stellar.js图像在查看之前就消失了

[英]Stellar.js images disappear before they are in view

EDIT: sample of the problem: https://codepen.io/wa23/pen/yooGyO Make the live render window as tall as possible to see the effect. 编辑:问题示例: https : //codepen.io/wa23/pen/yooGyO使实时渲染窗口尽可能高以查看效果。 Start scrolling from the picture of earth and by the time you get to the 3rd div, the image is already shifted so that it is almost out of view entirely. 从地球图片开始滚动,到第3格时,图像已经偏移,因此几乎完全看不见。

I have 4 divs like so: 我有4个div,如下所示:

<div data-stellar-background-ratio="0.5"></div>
<div class="plain"></div>
<div data-stellar-background-ratio="0.5"></div>
<div class="plain"></div>

The first and third rectangular div will have a background image that is parallaxed via Stellar.js, with other two do no, IE, they are staggered. 第一个和第三个矩形div的背景图像将通过Stellar.js进行视差处理,而其他两个div则不行,即IE,它们是交错的。

The problem is, by the time I scroll to the 3rd div, stellar js has already put my background image way out of view, both of the stellar divs have this property: 问题是,当我滚动到第3个div时,恒星js已经使我的背景图像看不见了,两个恒星div都具有以下属性:

background-position: 0px 745.5px; which is fine for the first div, since it is already out of the view frame, but doesn't work for the 3rd, because by the time you get there, it's background image has already been shifted vertically by 745px. 这对于第一个div来说很好,因为它已经超出了视图框架,但不适用于第三个div,因为到您到达那里时,它的背景图像已经垂直移动了745px。

I tried using data-stellar-vertical-offset="some number" with different values for the offset, but it doesnt work consistently across all viewport heights. 我尝试使用data-stellar-vertical-offset="some number"对偏移使用不同的值,但是它不能在所有视口高度上一致地工作。 1900 is what it takes for my 27 inch monitor, but it needs half that for my 15 inch laptop. 我的27英寸显示器需要1900,但15英寸笔记本电脑则需要1900。 I'm not sure what to do about this. 我不确定该怎么办。

Here is you answer, Change those properties, 这是您的答案,更改这些属性,

No.1 Set background-attachment: fixed; No.1设置background-attachment: fixed;

div:nth-of-type(odd) { 
  height: 150vh;
  width:100%;
  background-size: cover;
  background-repeat:no-repeat;
  background-attachment: fixed;
}

No.2 in js, js中的第二名,

$.stellar({
horizontalScrolling:false,
scrollProperty: 'transform'
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM