【发布时间】:2014-11-04 15:17:01
【问题描述】:
假设我想设计一个有四张幻灯片的网站。我希望每张幻灯片在访问者滚动时覆盖前一张。以下是 stellar.js(一个 jquery 插件)的尝试:http://jsfiddle.net/8mxugjqe/。你可以看到它适用于第一张幻灯片,第二张幻灯片覆盖了它,但我无法让它适用于其他幻灯片。
HTML:
<body>
<div id="one" data-stellar-ratio=".2">
<p>This is the first div.</p>
</div>
<div id="two" data-stellar-ratio="1">
<p>This is the second one.</p>
</div>
<div id="three">
<p>Third one!</p>
</div>
<div id="four">
<p>Fourth and last.</p>
</div>
</body>
CSS:
* {
margin: 0;
padding: 0;
}
#one, #two, #three, #four {
position: absolute;
height: 100%;
width: 100%;
font-size: 5em;
}
p {
margin: 1em;
width: 60%;
}
#one {
background: red;
}
#two {
background: blue;
top: 100%;
}
#three {
background: green;
top: 200%;
}
#four {
background: yellow;
top: 300%;
}
【问题讨论】:
-
data-stellar-ratio属性只控制元素滚动的速度。1的值表示元素将以正常速度滚动,.2的值表示元素将以正常速度的 20% 滚动,等等。我不认为你可以用这个来实现你在找什么。基本上,您需要滚动每张幻灯片,直到它到达浏览器窗口的顶部,然后停止滚动。您可能可以使用 stellar 和一些 jQuery 以编程方式修改data-stellar-ratio值来实现这一点。 -
看起来
data-stellar-vertical-offset属性可以帮助我实现我想要的,但你可能是对的。事实上,stellar.js 只是一个例子。我对其他技术持开放态度。这也是我最初没有添加 stellar.js 作为标签的原因(后来 j08691 添加了它)。
标签: javascript css stellar.js