Skip to content

jQuery plugin to detect if an element is in the viewport

License

Notifications You must be signed in to change notification settings

craigerskine/jquery-in-viewport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Requires jQuery.

Usage

$(selector).inViewport('#');

selector = your element you'd like to watch
# = an integer to offset the tolerance

Example

$(window).on('resize scroll', function() {
  $('.blah').each(function() {
    if($(this).inViewport('-150')) {
      $(this).addClass('inview');
    } else {
      $(this).removeClass('inview');
    }
  });
});

This will add a class called "inview" to the .blah elements after they are 150px inside the viewport on browser scroll and/or resize.

About

jQuery plugin to detect if an element is in the viewport

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks