JSFiddle - React, Tailwind, and code Playground
by Matteo Melillo
HTML
<section class="nivo-slider">
<a class="prev" href="javascript:void(0);">«</a>
<a class="next" href="javascript:void(0);">»</a>
<div class="nivo">
<div class="element slide1"></div>
<div class="element slide2"></div>
<div class="element slide3"></div>
<div class="element slide4"></div>
<div class="element slide5"></div>
</div>
</section>
CSS
.navi{ position:absolute; top:auto; bottom:-20px; z-index:300; right:0; }
.navi a{
display:block;
background:#000;
-webkit-border-radius:10px;
-moz-border-radius:10px;
-ms-border-radius:10px;
-o-border-radius:10px;
border-radius:10px;
border:none;
width:11px;
height:11px;
text-indent:-999em;
overflow:hidden;
margin:8px 5px 0 0;
cursor:pointer;
float:left;
}
.navi a.active, .navi a:hover{ background-color:red; }
.nivo-slider{
position:relative;
margin: 30px auto 0;
width:620px;
height: 460px;
}
.nivo{
position: relative;
overflow: hidden;
width: 620px;
height: 460px;
}
.nivo .element {
opacity: 1;
filter: alpha(opacity = 0);
display: none;
position: absolute;
top: 0;
left: 0;
width: 640px;
height: 460px;
zoom: 1;
}
.prev{
position: absolute;
top: 185px;
left: -40px;
cursor: pointer;
color:#000;
font-size:50px;
line-height:normal;
text-decoration:none;
}
.next{
position: absolute;
top: 185px;
line-height:normal;
right: -40px;
cursor: pointer;
color:#000;
font-size:50px;
text-decoration:none;
}
.nivo .slide1 {
display:block;
background-image: #4e4e48;
background-image: -webkit-linear-gradient(bottom right, #de55d7 0%, #0d9602 100%, #000000 100%);
background-image: -moz-linear-gradient(bottom right, #de55d7 0%, #0d9602 100%, #000000 100%);
background-image: -o-linear-gradient(bottom right, #de55d7 0%, #0d9602 100%, #000000 100%);
background-image: -ms-linear-gradient(bottom right, #de55d7 0%, #0d9602 100%, #000000 100%);
background-image: linear-gradient(bottom right, #de55d7 0%, #0d9602 100%, #000000 100%);
}
.nivo .slide2 {
background-image: #6a7259;
background-image: -webkit-linear-gradient(top left, #eb622d 0%, #52f5df 100%, #000000 100%);
background-image: -moz-linear-gradient(top left, #eb622d 0%, #52f5df 100%, #000000 100%);
...
JavaScript
window.addEvent('domready', function() {
var Nivo = new Class({
counter: 0,
initialize: function ( slider, next, prev ) {
this.slider = slider;
this.next = next;
this.prev = prev;
this.elements = this.slider.getElements('.element');
this.nEle = this.elements.length;
},
fadeOut: function(element) {
element.dissolve();
},
fadeIn: function(element) {
element.reveal();
},
getElementPosition: function(direction) {
if ( direction == '+') {
if ( this.counter == this.nEle-1) {
this.counter = 0;
} else {
this.counter++;
};
} else if ( direction == '-') {
if ( this.counter == 0 ) {
this.counter = this.nEle-1;
} else {
this.counter--;
}
};
nextSlide = this.elements[ this.counter ];
return nextSlide;
},
nextElement: function() {
this.next.addEvent('click', function() {
this.fadeOut(this.elements[this.counter]);
nextSlide = this.getElementPosition('+');
this.fadeIn(nextSlide);
}.bind(this));
},
prevElement: function() {
this.prev.addEvent('click', function() {
this.fadeOut(this.elements[this.counter]);
nextSlide = this.getElementPosition('-');
this.fadeIn(nextSlide);
}.bind(this));
},
play: function() {
this.nextElement();
this.prevElement();
}
});
var Navigator = new Class({
Extends: Nivo,
navi: {},
circles: [],
nextElement: function() {
this.next.addEvent('click', function( event ) {
this.fadeOut(this.elements[this.counter]);
this.circles[ this.counter ].removeClass('active');
nextSlide = this.getElementPosition('+');
this.fadeIn(nextSlide);
this.circles[ this.counter ].addClass('active');
}.bind(this));
},
prevElement: function() {
this.prev.addEvent('click', function( event ) {
this.fadeOut(this.elements[this.counter]);
this.circles[ this.counter ].removeClass('active');
nextSlide =...