Web Development

Identify If you are not at the top of a webpage while it loads or refresh and add class to a Div or HTML Elements using jQuery

Suppose you are visiting a page and you scrolled to a portion of that page, now if you refresh or reload the page, you need to check you are not at the top of the website
and add a class to a HTML Elements. So This jQuery code will help you achieve this.

	<script>
	jQuery(document).ready(function(){
		 
 
    var windowpos = jQuery(window).scrollTop();
	console.log(windowpos);
      
      if(windowpos>100){
        jQuery('CLASS OR ID OF HTML ELEMENTS').addClass('CLASS YOU WANT TO ADD');
      }
 }); 	
 </script>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s