我期待实现在这个页面上使用的文本效果在“精心设计的创意”部分,在那里的文本幻灯片和消失在滚动,我如何做到这一点?见本页:http://www.fiftythree.com/pencil
同时也希望能在手机上实现这一目标。
谢谢!
发布于 2013-12-01 09:06:03
在scroll()上获取窗口scrollTop()值,然后与每个元素top position()进行比较。如果scrollTop()大于某个元素,则top position应用动画/衰落。
如果你有这样的标记。
<div>
<section>First</section>
<section>Second</section>
<section>Third</section>
<section>Fourth</section>
<section>Fifth</section>
</div>这就是解决办法:
$(window).scroll(function(){
var st = $(this).scrollTop(),
winH = $(this).height(),
/* you can set this add,
depends on where you want the animation to start
for example if the section height is 100 and you set add of 50,
that means if 50% of the section is revealed
on the bottom of viewport animate text
*/
add = 150;
$('section').each(function(){
var pos = $(this).position().top;
if(st + winH >= pos + add){
$(this).stop().animate({opacity:1, marginTop:10},'fast');
}else{
$(this).stop().animate({opacity:0, marginTop:0},'fast');
}
});
});参见此小提琴
https://stackoverflow.com/questions/20295689
复制相似问题