отлично работает, только если надо вывести 2 значения в alert
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<style>
span{
display: block;
margin: 150px 0;
}
</style>
</head>
<body>
<div class="div"><span class="a1">1</span><span class="b1">a</span></div>
<div class="div"><span class="a1">2</span><span class="b1">b</span></div>
<div class="div"><span class="a1">3</span><span class="b1">c</span></div>
<div class="div"><span class="a1">4</span><span class="b1">d</span></div>
<div class="div"><span class="a1">5</span><span class="b1">e</span></div>
<script>
var arr = [];
function inWindow(){
var st = $(window).scrollTop();
$('.div').each(function(){
var offset = $(this).offset();
p=$(this).children().find('.a1').text();
o=$(this).children().find('.b1').text();
if(st <= offset.top && ($(this).height() + offset.top) < (st + $(window).height()) && !arr.includes(p.''.o)){
arr.push(p.''.o);
}
alert(p.''.o);
});
}
onscroll = inWindow;
onresize = inWindow;
</script>
</body>
</html>
надо тоже самое выводить только элементы массива которые еще не показывались только 2 переменные a1 и b1 можно через -