Skip to content

Instantly share code, notes, and snippets.

@dariocravero
Created December 2, 2012 20:45
Show Gist options
  • Save dariocravero/4190980 to your computer and use it in GitHub Desktop.
Save dariocravero/4190980 to your computer and use it in GitHub Desktop.
A CodePen by Darío Javier Cravero.
<div class=hover-me>HOVER THIS</div>
<div class=helper></div>
var helpers = ['Hover 1', 'Hover 2', 'Hover 3'],
index = 0,
time = 2000,
start_over = false,
interval, timeout;
$('.hover-me').on('mouseover', function() {
$('.helper').addClass('active').text(helpers[index++]);
interval = setInterval(function() {
if (index > helpers.length) index = 0;
$('.helper').addClass('transition');
timeout = setTimeout(function() {
$('.helper').text(helpers[index++]).removeClass('transition');
}, time/4);
}, time);
}).on('mouseout', function() {
$('.helper').removeClass('active transition').text('');
clearInterval(interval);
clearTimeout(timeout);
index = start_over ? 0 : index-1;
});
.helper {
-webkit-transition: opacity 0.5s ease-in-out;
opacity: 0;
}
.helper.active {
opacity: 1;
}
.helper.transition {
opacity: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment