JSFiddle - React, Tailwind, and code Playground
HTML
<div id="page-wrap">
<button>Rotating Blocks</button>
<p>Click on the smaller blocks on right to rotate. Browsers that support transitions will unleash radness, otherwise, hey, it still works.</p>
<div id="rotator">
<div id="block-1" class="active">
<h2>Subtitle #1</h2>
<div>
<h1>Seven Space Frogs Descend On Canada's Largest City</h1>
<img src="spacefrog.jpg" alt="space frog">
<p>Commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
</div>
<div id="block-2" class="active2">
<h2>Subtitle #2</h2>
<div>
<h1>The Power of the Voodoo. Who do? You do.</h1>
<img src="goblins.jpg" alt="goblins">
<p>Ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
</div>
<div id="block-3" class="active3">
<h2>Subtitle #3</h2>
<div>
<h1>You May Find Yourself Living in a Shotgun Shack</h1>
<p>Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis...
CSS
* { margin: 0; padding: 0; }
html { background: #fff3c9; }
body { font: 14px/1.4 Georgia, serif; color: #2d2d2d; }
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
#page-wrap { width: 960px; margin: 80px auto; }
h1 { font: bold 36px Helvetica, Arail, Sans-Serif; letter-spacing: -1px; }
h1, p { margin: 0 0 20px 0; }
#rotator { width: 677px; height: 605px; position: relative; background: white; padding: 20px; }
#block-1 { background: #ccc ; }
#block-2 { background: #ccc; }
#block-3 { background: #ccc; }
#block-4 { background: #ccc; }
#block-5 { background: #ccc; }
#block-6 { background: #ccc; }
#block-7 { background: #ccc; }
#block-8 { background: #ccc; }
#rotator > div {
position: absolute;
overflow: hidden;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
}
#rotator > div > div {
padding: 20px;
}
#rotator > div > div img {
float: right;
margin: 0 0 2px 10px;
}
#rotator .active {
height: 231px;
left: 22px;
top: 20px;
width: 331px;
}
#rotator .active2 {
height: 231px;
left: 367px;
top: 20px;
width: 331px;
}
#rotator .active3 {
height: 231px;
left: 20px;
top: 268px;
width: 331px;
}
#rotator .active4 {
height: 231px;
left: 367px;
top: 268px;
width: 331px;
}
#rotator .non-active-1 {
height: 112px;
left: 20px;
top: 517px;
width: 160px;
}
#rotator .non-active-2 {
height: 112px;
left: 192px;
top: 515px;
width: 160px;
}
#rotator .non-active-3 {
height: 112px;
left: 365px;
top: 515px;
width: 160px;
}
#rotator .non-active-4 {
height: 112px;
left: 538px;
top: 515px;
width: 160px;
}
#rotator .non-active-1:hover, #rotator .non-active-2:hover, #rotator .non-active-3:hover, #rotator .non-active-4:hover {
cursor: pointer;
-webkit-box-shadow: 0 0 10px rgba(0,0,0,0.4);
-moz-box-shadow: 0 0 10px rgba(0,0,0,0.4);...
JavaScript
jQuery.fn.rotateClasses = function(classes) {
var currentRotation = 1;
var rotateFn = function() {
var len = classes.length;
var cycle = currentRotation++ % len;
this.find('> div').each(function(id,div){
$(div).removeClass().addClass(classes[(cycle+id)%len]);
});
if(max > 0 && currentRotation > max);
};
$(button).onClick(rotateFn.bind($(this)));
return this;
};
$('#rotator').rotateClasses(["active", "active2", "active3", "active4", "non-active-1", "non-active-2", "non-active-3", "non-active-4"])