feat: 加强 carousel 组件
This commit is contained in:
@@ -35,7 +35,7 @@ const props = withDefaults(defineProps<LayButtonProps>(), {
|
||||
loading: false,
|
||||
disabled: false,
|
||||
nativeType: "button",
|
||||
borderStyle: "soild"
|
||||
borderStyle: "soild",
|
||||
});
|
||||
|
||||
const emit = defineEmits(["click"]);
|
||||
@@ -47,10 +47,10 @@ const onClick = (event: any) => {
|
||||
};
|
||||
|
||||
const styles = computed(() => {
|
||||
return {
|
||||
border: `1px ${props.borderStyle}`
|
||||
}
|
||||
})
|
||||
return {
|
||||
border: `1px ${props.borderStyle}`,
|
||||
};
|
||||
});
|
||||
|
||||
const classes = computed(() => {
|
||||
return [
|
||||
@@ -82,4 +82,4 @@ const classes = computed(() => {
|
||||
<slot v-else></slot>
|
||||
<i v-if="suffixIcon" :class="`layui-icon ${suffixIcon}`"></i>
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
@@ -86,13 +86,10 @@ provide("slotsChange", slotsChange);
|
||||
// 上一页
|
||||
const sub = function () {
|
||||
for (var i = 0; i < childrens.value.length; i++) {
|
||||
// @ts-ignore
|
||||
if (childrens.value[i].props.id === active.value) {
|
||||
if (i === 0) {
|
||||
// @ts-ignore
|
||||
active.value = childrens.value[slots.length - 1].props.id;
|
||||
}
|
||||
// @ts-ignore
|
||||
active.value = childrens.value[i - 1].props.id;
|
||||
break;
|
||||
}
|
||||
@@ -102,18 +99,36 @@ const sub = function () {
|
||||
// 下一页
|
||||
const add = function () {
|
||||
for (var i = 0; i < childrens.value.length; i++) {
|
||||
// @ts-ignore
|
||||
if (childrens.value[i].props.id === active.value) {
|
||||
if (i === childrens.value.length - 1) {
|
||||
// @ts-ignore
|
||||
active.value = childrens.value[0].props.id;
|
||||
}
|
||||
// @ts-ignore
|
||||
active.value = childrens.value[i + 1].props.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 自动播放
|
||||
const autoplay = () => {
|
||||
for (var i = 0; i < childrens.value.length; i++) {
|
||||
if (childrens.value[i].props.id === active.value) {
|
||||
if (i === childrens.value.length - 1) {
|
||||
active.value = childrens.value[0].props.id;
|
||||
}
|
||||
active.value = childrens.value[i + 1].props.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.autoplay,
|
||||
() => {
|
||||
setInterval(autoplay, props.interval);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -262,7 +262,7 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
}
|
||||
.scrollbar-y ::-webkit-scrollbar{
|
||||
.scrollbar-y ::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
//移动端隐藏自定义滚动条
|
||||
@@ -270,10 +270,10 @@ export default defineComponent({
|
||||
display: none;
|
||||
}
|
||||
//移动端显示原生滑块
|
||||
.hide.scrollbar-box .scrollbar-y ::-webkit-scrollbar{
|
||||
.hide.scrollbar-box .scrollbar-y ::-webkit-scrollbar {
|
||||
display: block;
|
||||
}
|
||||
.hide.scrollbar-box .scrollbar-y .scroll-wrap{
|
||||
.hide.scrollbar-box .scrollbar-y .scroll-wrap {
|
||||
scrollbar-width: auto;
|
||||
-ms-overflow-style: scrollbar;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user