Jump to content
Search Community

Hover on one element and transition sibling elements

aok test
Moderator Tag

Recommended Posts

I'm attempting to allow that if the user hovers on one element, it then transitions the other elements (siblings). I'm doing this with mouseenter/mouseleave.

 

const dev = {};

dev.interactions = {
  init: function() {
    this.bindEvents();
  },

  bindEvents: function() {

    let $filters = document.querySelectorAll("[data-filters] a");
    $filters.forEach(function($filter) {
      let $filters = [
          ...$filter.closest("[data-filters]").querySelectorAll("[data-filter]")
        ],
        $filterSiblings = $filters.filter(function(filter) {
          return filter !== $filter;
        }),
        filtering = gsap
          .to($filterSiblings, 0.4, {
            css: {
              color: "#ece9e2"
            }
          })
          .pause();

      $filter.addEventListener("mouseenter", function(e) {
        dev.interactions.filtersOnEnter(filtering);
      });

      $filter.addEventListener("mouseleave", function(e) {
        dev.interactions.filtersOnLeave(filtering);
      });
    });

  },

  filtersOnEnter: function(filtering) {
    filtering.play();
  },

  filtersOnLeave: function(filtering) {
    filtering.reverse();
  }
};
dev.interactions.init();

 

The issue is I think the timing out or start/stop of the animation? I've tried a variation of approaches but with each I can't seem to work out what's going wrong? Any pointers?

See the Pen PoqOozR by johnthepainter (@johnthepainter) on CodePen

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...