console
$(document).ready(function(){
$.fn.JudgmentElement = function () {
var winHeight = $(window).height();
var elTop = $(this).get(0).getBoundingClientRect().top;
var elBottom = $(this).get(0).getBoundingClientRect().bottom;
if( elTop < winHeight && elBottom > 0 ){
$(".watch-result").html("看得见");
}else{
$(".watch-result").html("看不见");
}
};
$(".watch-el").JudgmentElement();
$(window).scroll( function() {
$(".watch-el").JudgmentElement();
} );
});
<div class="test-box">
<div class="watch-result"></div>
<div class="watch-el">
我是被观看的元素
</div>
</div>
body{
margin: 0;
}
.test-box{
position: relative;
min-height: 200vh;
color: #fff;
background:#666;
}
.test-box .watch-el{
position: absolute;
top: 50vh;
left: 50%;
border: 1px solid #fff;
}
.test-box .watch-result{
position: fixed;
top: 50vh;
left: 0;
color: #000;
background: #fff;
}