oleg901,
<!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;
}
</style>
<script>
window.addEventListener("DOMContentLoaded", function() {
[].forEach.call(document.querySelectorAll(".carousel"), function(el) {
var img = JSON.parse(el.dataset.src),
len = img.length,
i = len - 1,
p = el.dataset.pause || 5E3,
t;
function g() {
i = ++i % len;
el.style.backgroundImage = "url(" + img[i] + ")";
el.classList.add("show");
t = window.setTimeout(k, p)
}
g();
function k() {
el.classList.remove("show");
t = window.setTimeout(g, 800)
}
el.addEventListener('mouseenter',
function() {
window.clearTimeout(t);
el.classList.add("show");
});
el.addEventListener('mouseleave', k)
})
});
</script>
</head>
<body>
<div class="carousel" data-pause="3000"
data-src='[
"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://www.fotki.ykt.ru/albums/userpics/2013/11-18/1384739526_image.jpg"]'>
</div>
<div class="carousel vertical" data-pause="3000" data-src='[
"http://static.mnogonado.net/images/img.php?w=250&l=%2Fstore%2Fimage%2F800x600_qdv_57108c999ba0b1775c4bfe263023fb6a_1474795-404.png",
"http://rugirlz.com/pics/hv_dp20088034.jpg"
]'>
</div>
</body>
</html>
|