提交 c1767a32 编写于 作者: Q qq_63480508

Thu Apr 3 17:20:00 CST 2025 inscode

上级 aa50c4cb
<script setup> <script setup>
import HelloWorld from './components/HelloWorld.vue' import HelloWorld from './components/HelloWorld.vue'
import TheWelcome from './components/TheWelcome.vue' // import TheWelcome from './components/TheWelcome.vue'
</script> </script>
<template> <template>
<header> <header>
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" /> <!-- <img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" /> -->
<div class="wrapper"> <div class="wrapper">
<HelloWorld msg="You did it!" /> <HelloWorld msg="You did it!" />
......
<script setup>
defineProps({
msg: {
type: String,
required: true
}
})
</script>
<template> <template>
<div class="greetings"> <div class="carousel">
<h1 class="green">{{ msg }}</h1> <div class="carousel-inner" :style="{ transform: `translateX(-${currentIndex * 100}%)` }">
<h3> <div class="carousel-item" v-for="(image, index) in images" :key="index">
You’ve successfully created a project with <img :src="image" alt="轮播图" />
<a target="_blank" href="https://vitejs.dev/">Vite</a> + </div>
<a target="_blank" href="https://vuejs.org/">Vue 3</a>. </div>
</h3> <div class="carousel-controls">
<button @click="prev"></button>
<button @click="next"></button>
</div>
<div class="carousel-indicators">
<span
v-for="(image, index) in images"
:key="index"
:class="{ active: index === currentIndex }"
@click="goTo(index)"
></span>
</div>
</div> </div>
</template> </template>
<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
const images = [
'https://image.so.com/ai/s?q=%E5%B9%B3%E5%8F%B0%E5%9B%BE%E7%89%87&listsrc=sobox&listsign=28c4844d972744afe424ff0172e943a0&src=360pic_strong',
'https://via.placeholder.com/800x400?text=Slide+2',
'https://via.placeholder.com/800x400?text=Slide+3',
'https://via.placeholder.com/800x400?text=Slide+4',
];
const currentIndex = ref(0);
const intervalTime = 3000;
let timer = null;
const next = () => {
currentIndex.value = (currentIndex.value + 1) % images.length;
};
const prev = () => {
currentIndex.value = (currentIndex.value - 1 + images.length) % images.length;
};
const goTo = (index) => {
currentIndex.value = index;
};
onMounted(() => {
timer = setInterval(() => {
next();
}, intervalTime);
});
onUnmounted(() => {
clearInterval(timer);
});
</script>
<style scoped> <style scoped>
h1 { .carousel {
font-weight: 500; position: relative;
font-size: 2.6rem; width: 800px;
top: -10px; height: 400px;
overflow: hidden;
margin: 0 auto;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.carousel-inner {
display: flex;
transition: transform 0.5s ease;
}
.carousel-item {
min-width: 100%;
box-sizing: border-box;
}
.carousel-item img {
width: 220px;
height: 220px;
object-fit: cover;
}
.carousel-controls {
position: absolute;
top: 50%;
width: 100%;
display: flex;
justify-content: space-between;
transform: translateY(-50%);
}
.carousel-controls button {
background: rgba(0, 0, 0, 0.5);
border: none;
color: #fff;
font-size: 2rem;
padding: 10px 15px;
cursor: pointer;
border-radius: 50%;
transition: background 0.3s;
}
.carousel-controls button:hover {
background: rgba(0, 0, 0, 0.7);
} }
h3 { /* 底部指示器 */
font-size: 1.2rem; .carousel-indicators {
position: absolute;
bottom: 15px;
left: 50%;
display: flex;
transform: translateX(-50%);
} }
.greetings h1, .carousel-indicators span {
.greetings h3 { display: inline-block;
text-align: center; width: 12px;
height: 12px;
margin: 0 5px;
background: rgba(255, 255, 255, 0.5);
border-radius: 50%;
cursor: pointer;
transition: background 0.3s;
} }
@media (min-width: 1024px) { .carousel-indicators span.active {
.greetings h1, background: rgba(255, 255, 255, 1);
.greetings h3 {
text-align: left;
}
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册