ciar4n / imagehover.css

Pure CSS Image Hover Effect Library
http://imagehover.io
MIT License
1.8k stars 234 forks source link

Can you trigger effect from a link outside the <figure class="imghvr"> element? #22

Closed bluebloc closed 5 years ago

bluebloc commented 5 years ago

How can you trigger the hover effect from a link outside the

element?

C-Lodder commented 5 years ago

You can probably get away with targetting the next element, like so: https://jsfiddle.net/fmaoe903/

Else you've have to change the hover puesdo class in the effects here: https://github.com/ciar4n/imagehover.css/blob/master/scss/effects/_imghvr-blur.scss#L7 to an actually class which gets appended using Javascript. Something like this:

SCSS:

.imghvr-blur {
    figcaption {
        opacity: 0;
    }
    &.hover {
        > img {
            filter: blur(30px);
            transform: scale(1.2);
            opacity: 0;
        }
        figcaption {
            opacity: 1;
            transition-delay: $transition-duration * 0.6;
        }
    }
}

HTML:

<figure class="imghvr-fade">
  <img src="#">
  <figcaption>
    // Hover Content
  </figcaption>
</figure>

Javascript:

const link = document.getElementById('link');
const figure = document.querySelector('.imghvr-blur');

link.addEventListener('mouseenter', () => {
  figure.classList.add('hover');
});
link.addEventListener('mouseleave', () => {
  figure.classList.remove('hover');
});