barbajs / barba

Create badass, fluid and smooth transitions between your website’s pages
https://barba.js.org/
MIT License
11.59k stars 477 forks source link

Double Click Issues #306

Closed jspraguedesigns closed 5 years ago

jspraguedesigns commented 6 years ago

Since implementing barba.js the user has to double click the arrows at the bottom to navigate if the user scrolled down. The first click scrolls to the top. The second click navigates to the next page. Not sure what the glitch is

View here: http://spraguedigitalcreative.com/silvergate-wordpress-theme-development/

`document.addEventListener("DOMContentLoaded", function() { var lastElementClicked; var PrevLink = document.querySelector('.prev-container'); var NextLink = document.querySelector('.next-container');

Barba.Pjax.init(); Barba.Prefetch.init();

Barba.Dispatcher.on('linkClicked', function(el) { lastElementClicked = el; });

var MovePage = Barba.BaseTransition.extend({ start: function() { this.originalThumb = lastElementClicked;

  Promise
    .all([this.newContainerLoading, this.scrollTop()])
    .then(this.movePages.bind(this));
},

scrollTop: function() {
  var deferred = Barba.Utils.deferred();
  var obj = { y: window.pageYOffset };

  TweenLite.to(obj, 0.4, {
    y: 0,
    onUpdate: function() {
      if (obj.y === 0) {
        deferred.resolve();
      }

      window.scroll(0, obj.y);
    },
    onComplete: function() {
      deferred.resolve();
    }
  });

  return deferred.promise;
},

movePages: function() {
  var _this = this;
  var goingForward = true;
  this.updateLinks();

  if (this.getNewPageFile() === this.oldContainer.dataset.prev) {
    goingForward = false;
  }

  TweenLite.set(this.newContainer, {
    visibility: 'visible',
    xPercent: goingForward ? 100 : -100,
    position: 'fixed',
    left: 0,
    top: 0,
    right: 0
  });

  TweenLite.to(this.oldContainer, 0.6, { xPercent: goingForward ? -100 : 100 });
  TweenLite.to(this.newContainer, 0.6, { xPercent: 0, onComplete: function() {
    TweenLite.set(_this.newContainer, { clearProps: 'all' });
    _this.done();
  }});
},

updateLinks: function() {
  PrevLink.href = this.newContainer.dataset.prev;
  NextLink.href = this.newContainer.dataset.next;
},

getNewPageFile: function() {
  return Barba.HistoryManager.currentStatus().url.split('/').pop();
}

});

Barba.Pjax.getTransition = function() { return MovePage; }; }); `

codymx commented 6 years ago

@jspraguedesigns Are you getting any console errors during the transition?

jspraguedesigns commented 6 years ago

None

Sent from my iPhone

On Sep 19, 2018, at 11:03 AM, Cody Marcoux notifications@github.com wrote:

@jspraguedesigns Are you getting any console errors during the transition?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

vin-ni commented 3 years ago

Has this been resolved?