嘿家伙即时尝试实现onscroll功能,但它不会在我的网站上工作。不透明度onscroll,脚本将不起作用
我到底做错了什么?
<head>
<script>
$(document).ready(function() {
/* Every time the window is scrolled ... */
$(window).scroll(function(){
/* Check the location of each desired element */
$('.hideme').each(function(i){
var bottom_of_object = $(this).position().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, fade it it */
if(bottom_of_window > bottom_of_object){
$(this).animate({'opacity':'1'},500);
}
});
});
});</script>
</head>
<body>
<div id="container">
<div class="hideme">Fade In</div>
<div class="hideme">Fade In</div>
<div class="hideme">Fade In</div>
<div class="hideme">Fade In</div>
<div class="hideme">Fade In</div>
</div>
</body>
,并链接到网站的全码: http://eren-web-design-development.tk/C-Html/landingpage/
哇这太棒了,非常感谢。它现在是适当的,但是有可能在滚动之后查看隐藏容器中的一个,第二个是如果进一步滚动则查看隐藏容器。等等? 非常感谢您的回答 – jasongrimes 2014-09-26 14:00:42
很酷。乐意效劳。你可以接受我的回答btw :) – Amit 2014-09-26 14:02:04
这不是完美的,但尝试这样: if($(this).position()。top <$(window).scrollTop()+ 400){( $此).animate({ '不透明': '1'},500); } – Amit 2014-09-26 14:14:44