56 lines
2.0 KiB
HTML
56 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>Aurora Admin · Carousel(普通 H5)</title>
|
||
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
|
||
<link rel="stylesheet" href="Carousel.css" />
|
||
<style>body{margin:0;padding:24px;background:#F5F7FA;}</style>
|
||
</head>
|
||
<body>
|
||
<div class="aa-carousel" id="app"></div>
|
||
|
||
<script>
|
||
var DATA = [
|
||
{ text: '促销活动一', color: '#2F54EB' },
|
||
{ text: '新品上市', color: '#13C2C2' },
|
||
{ text: '会员专享', color: '#722ED1' },
|
||
{ text: '限时秒杀', color: '#FA8C16' }
|
||
];
|
||
var index = 0, timer = null;
|
||
|
||
function render() {
|
||
var root = document.getElementById('app');
|
||
var slides = DATA.map(function (d) {
|
||
return '<div class="aa-carousel-slide" style="background:' + d.color + '">' + d.text + '</div>';
|
||
}).join('');
|
||
var dots = DATA.map(function (_, i) {
|
||
return '<span class="aa-carousel-dot ' + (i === index ? 'is-active' : '') + '" data-i="' + i + '"></span>';
|
||
}).join('');
|
||
root.innerHTML = '<div class="aa-carousel-track" style="transform:translateX(-' + (index * 100) + '%)">' + slides + '</div>' +
|
||
'<button class="aa-carousel-arrow prev">‹</button>' +
|
||
'<button class="aa-carousel-arrow next">›</button>' +
|
||
'<div class="aa-carousel-dots">' + dots + '</div>';
|
||
|
||
root.querySelector('.prev').onclick = function () { go(index - 1); };
|
||
root.querySelector('.next').onclick = function () { go(index + 1); };
|
||
root.querySelectorAll('.aa-carousel-dot').forEach(function (d) {
|
||
d.onclick = function () { go(parseInt(d.dataset.i, 10)); };
|
||
});
|
||
}
|
||
function go(i) {
|
||
index = (i + DATA.length) % DATA.length;
|
||
render();
|
||
restart();
|
||
}
|
||
function restart() {
|
||
if (timer) clearInterval(timer);
|
||
timer = setInterval(function () { go(index + 1); }, 3000);
|
||
}
|
||
render();
|
||
restart();
|
||
</script>
|
||
</body>
|
||
</html>
|