Category: jQuery

jQuery: check if element is visible on screen

<div class=”container”> <div class=”text text-1″> Lorem ipsum <span></span> </div> <div class=”text text-2″> Lorem ipsum <span></span> </div> </div> .container { height: 100rem; } .container .text { text-align: center; font-size: 1.5rem; } .container .text.text-1 { margin-top: 5rem; } .container .text.text-2 { margin-top: 50rem; } .container .text span { color: #f20; } $(window).scroll(function(){ $(‘.text’).each(function(){ if(isScrolledIntoView($(this))){ $(this).children(‘span’).text(‘visible’); } else{ […]