我想使用jquery函数,但是我无法解析.each()函数。我有JQuery-3.4.1.js文件,所以我不确定我需要另一个文件吗?
$(function(){
$(window).scroll( function(){
/* Check the location of each desired element */
$('.hideme').each( function(i){
var bottom_of_object = $(this).offset().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);
}
});
});
});
甚至在3.4.1上也无法识别吗?我对此并不陌生,所以可能会遗漏一些明显的东西...
在function(i)
和each
参数中查找e
:
//Im adding i,e (i => index, e => theElement) // NOT $(this)
$('.hideme').each( function(i,e){
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window > bottom_of_object ){
//Im changing $(this) to $(e)
$(e).animate({'opacity':'1'},500);
}
});