Posted in jquery
19
12:24 am, December 1, 2020

using jquery appear for checking if an element is visible on screen

Yes.. sometimes i like using jquery as well, as it can make things so easy! :)

Here is a quick demo using the JQuery Appear plugin so make an element change if it on or off screen. 

Plugin Link: https://cdnjs.com/libraries/jquery.appear 

This requires JQuery and also a Document Ready

* Still trying to get this demo code working properly

HTML

<div class="moo" id="moo">I Am Hidden (almost)</div>

CSS

.moo {
 height:100px;
 width:300px;
 border:3px solid #333;
 padding:30px;
 border-radius:3px;
 text-align:center;
}

Scripts

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.appear/0.4.1/jquery.appear.js" integrity="sha512-dPZE9SLz1NVUX9tSX9TYOs2SyaJRBZC9ogOc/VasDFSFrxSDkXv3ZCdgkG8/AzHQ+YVklyqDgSS3aDgMradlNg==" crossorigin="anonymous"></script>

Javascript

$(document).ready(function(){
  $('#moo').on('appear', function(event, $all_appeared_elements) {
    // this element is now inside browser viewport
    $("#moo").text("i am visible");
  });
  $('someselector').on('disappear', function(event, $all_disappeared_elements) {
    // this element is now outside browser viewport
    $("#moo").text("i am <b>NOT</b> visible");
  });
});

/*
$(document).ready(function(){
 $('#moo').appear(function() {
  $("#moo").text("moo");
 });
});
$('<div>test</div>').appear();
*/
I Am Hidden (almost)

View Statistics
This Week
46
This Month
163
This Year
0

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

Join me on Substack if you want me to send you a collection of the things i have done or found or read for the week. Or follow me on twitter if you prefer, i dont post much but i probably should!

❤👩‍💻🕹

Random Quote
In this case my anchor this week becomes driving almost 2hrs outside of Atlanta to one of my favorite hard core gyms in the world.. MetroFlex aka The Dungeon. The gym owners turn the heat way up so it becomes a fun sweat box and the gym members just watch from afar and leave me alone. I happily drive myself long distances to find MY ANCHOR. Our anchor allows us to have balance, focus and be as productive as possible. And if you're in the middle of a heavy set and your headphones start to fall off your head, like mine did here.. well.. f*ck the headphones. Let em break and fall. You can always get a new pair, but the iron ain't ever gonna lift itself.
Unknown