layui/examples/carousel.html

124 lines
2.5 KiB
HTML
Raw Normal View History

2017-08-21 08:51:13 +08:00
<!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>
2021-05-31 08:57:00 +08:00
2017-08-21 08:51:13 +08:00
<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>
2022-06-23 00:03:41 +08:00
<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>
2017-08-21 08:51:13 +08:00
</div>
</div>
<script src="../src/layui.js"></script>
<script>
layui.use('carousel', function(){
var carousel = layui.carousel;
//建造实例
carousel.render({
elem: '#test1'
,index: 2
//,full: true
,arrow: 'always'
2022-06-23 00:03:41 +08:00
,autoplay: 'always'
,change: function(obj){
console.log(obj)
}
2019-05-31 14:36:29 +08:00
//,interval: 5000
2017-08-21 08:51:13 +08:00
//,autoplay: false
//,indicator: 'outside'
//,trigger: 'hover'
});
//事件
2022-06-23 00:03:41 +08:00
/*
carousel.on('change(test1)', function(obj){
console.log(obj)
2017-08-21 08:51:13 +08:00
});
2022-06-23 00:03:41 +08:00
*/
2017-08-21 08:51:13 +08:00
carousel.render({
elem: '#test2'
,interval: 1800
//,full: true
,anim: 'fade'
,height: '120px'
});
carousel.render({
elem: '#test3'
//,full: true
,arrow: 'always'
//,autoplay: false
//,indicator: 'outside'
//,trigger: 'hover'
,anim: 'updown'
//,full: true
});
2022-06-23 00:03:41 +08:00
// 图片轮播
2017-08-21 08:51:13 +08:00
carousel.render({
elem: '#test4'
2022-06-23 00:03:41 +08:00
,width: '720px'
,height: '360px'
2017-08-21 08:51:13 +08:00
,interval: 5000
});
});
</script>
</body>
</html>