gpt4 book ai didi

javascript - 如何使用 Skrollr.js 实现多视差滚动

转载 作者:行者123 更新时间:2023-11-28 06:02:39 24 4
gpt4 key购买 nike

我对如何实现 skrollr.js 的理解有点问题。

我只想获得与此相同的效果:仅多视差。

如何实现这样的事情:

http://prinzhorn.github.io/skrollr/

我尝试在 CodePen 中使用这个,但它不像上面的示例那样滚动。

HTML

<body style="height:1200px;">
<div id="bg1" data-0="background-position:0px 0px;" data-end="background-position:-500px -10000px;" class="skrollable skrollable-between" style="background-position: 0px 0px;"></div>
<div id="bg2" data-0="background-position:0px 0px;" data-end="background-position:-500px -10000px;" class="skrollable skrollable-between" style="background-position: 0px 0px;"></div>
<div id="bg3" data-0="background-position:0px 0px;" data-end="background-position:-500px -10000px;" class="skrollable skrollable-between" style="background-position: 0px 0px;"></div>
</body>

<script src="https://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="https://prinzhorn.github.io/skrollr/dist/skrollr.min.js"></script>

CSS

#bg1, #bg2, #bg3 {
z-index: 50;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(https://prinzhorn.github.io/skrollr/examples/images/bubbles.png) repeat 0 0;
}

#bg2 {
z-index: 49;
background-image: url(https://prinzhorn.github.io/skrollr/examples/images/bubbles2.png);
}

#bg3 {
z-index: 48;
background-image: url(https://prinzhorn.github.io/skrollr/examples/images/bubbles3.png);
}

.skrollable {
/*
* First-level skrollables are positioned relative to window
*/
position:fixed;

/*
* Skrollables by default have a z-index of 100 in order to make it easy to position elements in front/back without changing each skrollable
*/
z-index:100;
}

.skrollr-mobile .skrollable {
/*
* May cause issues on Android default browser (see #331 on GitHub).
*/
position:absolute;
}

.skrollable .skrollable {
/*
* Second-level skrollables are positioned relative their parent skrollable
*/
position:absolute;
}

.skrollable .skrollable .skrollable {
/*
* Third-level (and below) skrollables are positioned static
*/
position:static;
}

JS

(function($){

skrollr.init();

})(jQuery);

希望您能赐教。不过我还是菜鸟。
谢谢!

最佳答案

我不知道这是否是你想要的视差效果,但是 here 可以帮助您解决并使用它。

此外,我还更新了您的代码,并使用 data-100-startdata-100-end 属性制作了多视差滚动演示。

<div id="bg1" data-100-start="background-position:0px 0px;" data-100-end="background-position:-500px -10000px;" class="skrollable skrollable-between" style="background-position: 0px 0px;"></div>
<div id="bg2" data-100-start="background-position:0px 0px;" data-100-end="background-position:-500px -10000px;" class="skrollable skrollable-between" style="background-position: 0px 0px;"></div>
<div id="bg3" data-100-start="background-position:0px 0px;" data-100-end="background-position:-500px -10000px;" class="skrollable skrollable-between" style="background-position: 0px 0px;"></div>

请引用此fiddle .

关于javascript - 如何使用 Skrollr.js 实现多视差滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37152744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com