laimas,
Annaboka,
вариант без остановки таймеров.(надобы прелоад добавить)
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.carousel{
width: 350px;
height: 170px;
position: relative;
opacity: 0;
border-radius: 8px;
box-sizing: border-box;
border: #8B4513 2px solid;
transition: opacity .8s ease-in;
background-size: 350px 170px;
}
.carousel.show{
opacity: 1;
}
.carousel.vertical{
width: 170px;
height: 350px;
background-size: 170px 350px;
}
.carousel h1{
color: #FFFFFF;
opacity: 0;
transition: .3s ease-in;
text-align: center;
bottom: 5px;
margin: auto 0;
transform: scale(0);
}
.carousel.pause h1{
opacity: 1;
transform: scale(1);
}
</style>
<script>
window.addEventListener("DOMContentLoaded", function() {
[].forEach.call(document.querySelectorAll(".carousel"), function(el) {
var img = JSON.parse(el.dataset.src),
text = JSON.parse(el.dataset.text);
len = img.length,
i = 0,
p = el.dataset.pause || 5E3,
h = document.createElement("h1");
el.appendChild(h);
function g() {
el.style.backgroundImage = "url(" + img[i] + ")";
h.textContent = text[i];
el.classList.add("show");
window.setTimeout(k, p);
}
g();
function k() {
el.classList.contains("pause") || (i = ++i % len, el.classList.remove("show"));
window.setTimeout(g, 800);
}
el.addEventListener("click", function() {
el.classList.toggle("pause");
});
});
});
</script>
</head>
<body>
<div class="carousel" data-pause="3000"
data-src='["http://sunnytravel.by/upload/image/Tours/Nicca-karnaval.jpg",
"http://img-fotki.yandex.ru/get/5640/35900228.10c/0_7388e_3ab59b4a_XL.jpeg.jpg",
"http://1.bp.blogspot.com/-aleHkBUuqOI/VY0HrCytsXI/AAAAAAAAq1g/f2emGtdqdWo/s640/2015-06-05_0145.jpg",
"http://turj.ru/images/e/3/9/7/1/b641b8a77c.jpg"]' data-text='["карнавал", "Ницца", "маска", "праздник"]'>
</div>
</body>
</html>