You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
layui/examples/carousel.html

126 lines
2.5 KiB

7 years ago
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>轮播组件 - layui</title>
<link rel="stylesheet" href="../src/css/layui.css">
<style>
body{padding: 20px;}
/* 为了区分效果 */
div[carousel-item]>*{text-align: center; line-height: 280px; color: #fff;}
div[carousel-item]>*:nth-child(2n){background-color: #009688;}
div[carousel-item]>*:nth-child(2n+1){background-color: #5FB878;}
#test2 div[carousel-item]>*{line-height: 120px;}
</style>
</head>
<body>
4 years ago
7 years ago
<div class="layui-carousel" id="test1" lay-filter="test1">
<div carousel-item>
<div>条目1</div>
<div>条目2</div>
<div>条目3</div>
<div>条目4</div>
</div>
</div>
<br>
<div class="layui-carousel" id="test2">
<div carousel-item>
<div>条目1</div>
<div>条目2</div>
</div>
</div>
<br>
<div class="layui-carousel" id="test3">
<div carousel-item>
<div>条目1</div>
<div>条目2</div>
<div>条目3</div>
<div>条目4</div>
</div>
</div>
<br>
<div class="layui-carousel" id="test4">
<div carousel-item>
2 years ago
<div><img src="https://unpkg.com/outeres/demo/carousel/720x360-1.jpg"></div>
<div><img src="https://unpkg.com/outeres/demo/carousel/720x360-2.jpg"></div>
<div><img src="https://unpkg.com/outeres/demo/carousel/720x360-3.jpg"></div>
<div><img src="https://unpkg.com/outeres/demo/carousel/720x360-4.jpg"></div>
<div><img src="https://unpkg.com/outeres/demo/carousel/720x360-5.jpg"></div>
7 years ago
</div>
</div>
<script src="../src/layui.js"></script>
<script>
layui.use('carousel', function(){
var carousel = layui.carousel;
// 实例
var carInst = carousel.render({
elem: '#test1',
index: 2,
// full: true,
arrow: 'always',
autoplay: 'always',
change: function(obj) {
2 years ago
console.log(obj)
},
// interval: 5000,
// autoplay: false,
// indicator: 'outside',
// trigger: 'hover'
7 years ago
});
// carInst.goto(1);
7 years ago
// 事件
2 years ago
/*
carousel.on('change(test1)', function(obj) {
2 years ago
console.log(obj)
7 years ago
});
2 years ago
*/
7 years ago
carousel.render({
elem: '#test2',
interval: 1800,
// full: true,
anim: 'fade',
height: '120px'
7 years ago
});
carousel.render({
elem: '#test3',
// full: true,
arrow: 'always',
// autoplay: false,
// indicator: 'outside',
// trigger: 'hover',
anim: 'updown',
// full: true
7 years ago
});
2 years ago
// 图片轮播
7 years ago
carousel.render({
elem: '#test4',
width: '720px',
height: '360px',
interval: 5000
7 years ago
});
});
</script>
</body>
</html>