<!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>
<span class="a1">1</span>
<span class="a1">2</span>
<span class="a1">3</span>
<span class="a1">4</span>
<span class="a1">5</span>
<script>
var arr = [];
function inWindow(){
var st = $(window).scrollTop();
$('.a1').each(function(){
var offset = $(this).offset();
if(st <= offset.top && ($(this).height() + offset.top) < (st + $(window).height()) && !arr.includes(this)){
arr.push(this);
alert(arr);
}
});
}
onscroll = inWindow;
onresize = inWindow;
</script>
</body>
</html>