JSFiddle - React, Tailwind, and code Playground

by Don Johnson

HTML

<div class="article">
    <div class="imageWrapper">
       
    </div>
</div>

CSS

.article[data-dir='expand'] .imageWrapper {
    transform:scale(1.24)
}

.article {
    background-color: #e6e6e6;
	overflow: hidden;
    width: 300px;
    height: 300px;
}

.imageWrapper {
    background-image: url('http://www.astutegraphics.com/images/blog/tutorials/widthscribe_patterns_18_mar_2013/floral-seamless-pattern.png');
    width: 300px;
    height: 300px;
    transform-origin: 50% 80%;
    transition:all 10.0s linear 0.0s;
}

JavaScript

/*
     1. on hover aka 'mouseenter' start the animation
     2. 10 seconds in, change direction of the animation
     3. on exit aka 'mouseleave', return to beginning
 */


var thisArticle = document.querySelector('.article'),
    thisTimer = '',
    isHovering = false;

thisArticle.addEventListener('mouseenter', function(){
    console.log('mouseenter');
    thisArticle.setAttribute('data-dir', 'expand');
    thisTimer = setInterval(fireAnimation, 10000);
    isHovering = true
}, false);

thisArticle.addEventListener('mouseleave', function(){
    console.log('mouseleave');
    thisArticle.removeAttribute('data-dir');
    isHovering = false;
}, false);

var fireAnimation = function(){
    if(isHovering){
        if(thisArticle.getAttribute('data-dir') === 'expand'){
            thisArticle.removeAttribute('data-dir');
        } else {
            thisArticle.setAttribute('data-dir', 'expand');
        }
    } else {
        clearInterval(thisTimer);
    }
    alert('change direction');
}