我正在尝试修改以下脚本,以使其对禁用 Javascript 的用户更友好。下面的代码在滚动位置将所有 div 的不透明度设置为 0 和 1。我想通过手动添加类'hideme'来隐藏特定的div并在滚动时显示它们。
$(document).ready(function() {
/* Hide all elements outside the visible window */
$('body *').each( function(){
var top_of_object = $(this).position().top;
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window < top_of_object ){
$(this).addClass('hideme').css({'opacity':'0'});
}
});
/* Every time the window is scrolled ... */
$(window).scroll( function(){
/* Check the location of the desired elements */
$('.hideme').each( function(i){
var bottom_of_object = $(this).position().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window > ( bottom_of_object + 20 ) ){
$(this).removeClass('hideme').animate({'opacity':'1'},500);
}
});
});
});
我想出了如何指定选定的 div,只需更改以下代码
$('body *').each(函数(){
至
$('.div-class,.another-div-class').each(function(){