![](/img/trans.png)
[英]How to get the position of screen window of browser when scroll down jquery
[英]jquery get window position + scroll - but if not scroll not show
嗨,几张照片显示在滚动条上。 我使用以下代码:
$(document).ready(function() {
$(window).scroll( function(){
$('.fade').each( function(i){
var bottom_of_object = $(this).position().top + ( $(this).outerHeight() / 2 );
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window > bottom_of_object ){
$(this).addClass('showme');
}
if( bottom_of_window < bottom_of_object ){
$(this).removeClass('showme');
}
});
});
});
这项工作效果很好,但是如果我打开页面(如果窗户太高),则照片不会显示出来,并且空间太难看了。 (我认为)是因为add类仅在窗口滚动上起作用。
我怎么解决这个问题? 当图片在Windows位置而不只是在滚动显示时,我需要吗?
谢谢!
将scroll
触发附加到代码:
$(document).ready(function() {
$(window).scroll( function(){
$('.fade').each( function(i){
var bottom_of_object = $(this).position().top + ( $(this).outerHeight() / 2 );
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window > bottom_of_object ){
$(this).addClass('showme');
}
if( bottom_of_window < bottom_of_object ){
$(this).removeClass('showme');
}
});
});
$(window).scroll();
});
$(window).scroll()
在window
- docs上触发scroll
事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.