Search code examples
javascriptjqueryjquery-masonryinfinite-scrolljquery-waypoints

Unable to turn off animation in jquery masonry + waypoint


Scrolling is working fine but I want to get rid of the animation.

I tried around all recommended solutions e.g. one mentioned here http://desandro.github.io/masonry/docs/animating.html but nothing worked.

Code for masonry:

<script src="{{asset('js/vendor/masonry.pkgd.min.js')}}"></script>
<script src="{{asset('js/vendor/waypoints.min.js')}}"></script>
<script src="{{asset('js/vendor/waypoints-infinite.js')}}"></script>
<script>
    $(window).load(function () {
        /*var container = $('.infinite-container');*/
        var container = $('.infinite-container').masonry({
            // options...
            itemSelector: '.wish-box',
            isAnimated: false,
            animated: false,
          });

        $('.infinite-container').waypoint('infinite', {
            container: 'auto',
            items: '.wish-box',
            more: '.infinite-more-link',
            offset: 'bottom-in-view',
            loadingClass: 'infinite-loading',
            onBeforePageLoad: $.noop,
            animate: false,
            onAfterPageLoad: function () {
                try {
                    container.masonry('reloadItems');
                    container.masonry('layout');
                } catch (err) {
                    alert(err.message);
                }
            }
        });
    });
</script>

Code for waypoints-infinite.js:

// Generated by CoffeeScript 1.6.2
/*
Infinite Scroll Shortcut for jQuery Waypoints - v2.0.5
Copyright (c) 2011-2014 Caleb Troughton
Licensed under the MIT license.
https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt
*/

var current_uri = window.location.pathname;

(function() {
  (function(root, factory) {
    if (typeof define === 'function' && define.amd) {
      return define(['jquery', 'waypoints'], factory);
    } else {
      return factory(root.jQuery);
    }
  })(window, function($) {
    var defaults;

    defaults = {
      container: 'auto',
      items: '.infinite-item',
      more: '.infinite-more-link',
      offset: 'bottom-in-view',
      loadingClass: 'infinite-loading',
      onBeforePageLoad: $.noop,
      onAfterPageLoad: $.noop
    };
    return $.waypoints('extendFn', 'infinite', function(options) {
      var $container, opts;

      opts = $.extend({}, $.fn.waypoint.defaults, defaults, options);
      if ($(opts.more).length === 0) {
        return this;
      }
      $container = opts.container === 'auto' ? this : $(opts.container);
      opts.handler = function(direction) {
        var $this;

        if (direction === 'down' || direction === 'right') {
          $this = $(this);
          opts.onBeforePageLoad();
          $this.waypoint('destroy');
          $container.addClass(opts.loadingClass);
          return $.get($(opts.more).attr('href'), function(data) {
            var $data, $more, $newMore, fn;

            $data = $($.parseHTML(data));
            $more = $(opts.more);
            $newMore = $data.find(opts.more);
            //append for wishes and prepend for messages
            if(current_uri.indexOf("messages") !== -1) {
                $container.prepend($data.find(opts.items));
            } else {
                $container.append($data.find(opts.items));
            }
            $container.removeClass(opts.loadingClass);
            if ($newMore.length) {
              $more.replaceWith($newMore);
              fn = function() {
                return $this.waypoint(opts);
              };
              setTimeout(fn, 0);
            } else {
              $more.remove();
            }
            return opts.onAfterPageLoad();
          });
        }
      };
      return this.waypoint(opts);
    });
  });

}).call(this);

Solution

  • It looks like your using Masonry v3 which has the animation options removed so isAnimated: false, animated: false are not relevant. You can use this:

       var container = $('.infinite-container').masonry({
            // options...
            itemSelector: '.wish-box',
           transitionDuration: 0
          });