I modified a couple of script ideas that I found here on SO to rotate or flip through several blocks of text (so visitors will not have to scroll) and to pause these when the user hovers. However, I am trying to set it up so that there are three different groups (blocks or divs) of rotating texts in the same view. I've given each group a different ID, but I'm not quite sure of how to add that level of behaviour to the script so that they're all going at the same time. I created a jsfiddle to show the basics of the code...as you will see only the first set (Joan) actually shows the text flipping, the other two (Shelly, Valerie) just sit there blank. Is there a simple fix in the javascript that would make all three of them work simultaneously? multi-group text rotation jsfiddle
function slideSwitch() {
var $active = $('.fadein quote.active');
if ($active.length == 0) $active = $('.fadein quote:last');
var $next = $active.next().length ? $active.next() : $('.fadein quote:first');
$active.addClass('last-active');
$next.css({
opacity: 0.0
})
.addClass('active')
.animate({
opacity: 1.0
}, 1000, function () {
$active.removeClass('active last-active');
});
}
$(function () {
var interval = setInterval(slideSwitch, 4000);
$('.fadein').hover(function () {
clearInterval(interval);
}, function () {
interval = setInterval(slideSwitch, 4000);
});
});
For this to work, you have to think in terms of Object Oriented Programming. See some documentation to learn more.
Look at this code. It gets the scroll to work on each person.