JSFiddle - React, Tailwind, and code Playground

by Mojtaba Sabeti

HTML

<span></span>
<div class="element"></div>

CSS

body{height:1000px}
.element{width:100px;height:100px;background:gold;position:relative;top:700px}
span{position:fixed;top:0}

JavaScript

$(document).ready(function(){

	$(window).on('scroll', function(){
		var scrollTop     = $(window).scrollTop(),
		    elementOffset = $('.element').offset().top,
      		distance      = (elementOffset - scrollTop),
     		height = $(window).height();
	
		$('span').text('اسکرول از بالا: ' + scrollTop + 'فاصله');
		
		if(distance < height){
			$('.element').fadeOut(1500);
		}
	});
});