Listen For Scroll Events And Fire Functions With Direction - jQuery scrollfy

File Size: 24.3 KB
Views Total: 440
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Listen For Scroll Events And Fire Functions With Direction - jQuery scrollfy

scrollfy is a small and mobile-friendly Is In View jQuery plugin which listens for page scroll (touch move) events and fires certain functions if elements are in or out of the viewport.

The main goal of this plugin is to create awesome scroll animations for your long web pages & single page applications.

How to use it:

1. To get started, include the minified version of the jQuery scrollfy plugin after jQuery library.

<script src="" 
<script src="jquery.scrollfy.min.js"></script>

2. Attach event listeners to the target element and do whatever you like when the elements is scrolled into or out of the viewport. Note that the Scrollfy function must be called at the last, after the event listeners as follows:

$(document).ready(function() {


  .on('scrollfy:scroll:begin', function(e) {
    $(this).removeClass('up down').addClass(e.scrollfy.direction);

  .on('scrollfy:inView', function(e) {
    if ( !$(this).hasClass('inview') ) {

  .on('scrollfy:offView', function(e) {
    if ( $(this).hasClass('inview') ) {

  .on('scrollfy:scroll:end', function(e) {
    $(this).removeClass('up down');


  $(window).on('scrollfy:scroll', function(e) {
    if ( e.scrollfy.direction == 'up' ) {
    } else if ( e.scrollfy.direction == 'down' ) {


3. All default plugin options.

  defaultOffset: 50,

  offsetAttrTop:     'scrollfy-offset-top',
  offsetAttrBottom:  'scrollfy-offset-bottom',

  eventNames: {
    scrollBegin:   'scrollfy:scroll:begin',
    scroll:        'scrollfy:scroll',
    scrollEnd:     'scrollfy:scroll:end',

    inView:        'scrollfy:inView',
    offView:       'scrollfy:offView',

  scrollTimeout:    250,
  directionTimeout: 50,
  listenTo:         'scroll touchmove resize',
  inviewIdentifier: 'scrollfy-inview'



  • fixed the inview calculation

This awesome jQuery plugin is developed by hendrikreimers. For more Advanced Usages, please check the demo page or visit the official website.