自定义轮播图

该代码段展示了一个使用纯JavaScript和CSS创建的图片幻灯片,具有自动切换和淡入淡出动画效果。幻灯片由三个相同的图片组成,每个图片都有对应的数字标签和点状导航。当鼠标悬停在页面上时,光标改变为自定义图像。
摘要由CSDN通过智能技术生成
<body>
    <div class="slideshow-container">
        <div class="mySlides fade">
            <div class="numbertext"> 1 / 3</div>
            <img src="C:\Users\123\Pictures\bgm.jpg" style="100%">
            <div class="text">文本 1</div>
        </div>  

        <div class="mySlides fade">
            <div class="numbertext"> 2 / 3</div>
            <img src="C:\Users\123\Pictures\bgm.jpg" style="100%">
            <div class="text">文本 1</div>
        </div>  

        <div class="mySlides fade">
            <div class="numbertext"> 3 / 3</div>
            <img src="C:\Users\123\Pictures\bgm.jpg" style="100%">
            <div class="text">文本 1</div>
        </div>     
    </div>
    <br>
    <div style="text-align: center">
        <span class="dot"></span>
        <span class="dot"></span>
        <span class="dot"></span>
    </div>
</body>
<script>
    var  slideIndex = 0;
    showSlides();
    function showSlides() {
        var i;
        var slides = document.getElementsByClassName("mySlides");
        var dots = document.getElementByClassName("dot");
        for(i=0; i < slides.length; i++) {
            slides[i].style.display = "none";
        }
        slideIndex++;
        if(slideIndex > slides.length) {
            slideIndex = 1
        }
        for(i = 0; i < dots.length; i++) {
            dots[i]className = dots[i].className.replace(" active", "")
        }
        slides[slideIndex - 1].style.display = "block"
        dots[slideIndex - 1].className += " active"
        setTimeout(showSlides, 2000) // 切换时间为2s
    }
</script>
<style>
*{
    box-sizing: border-box;
}
body {
    font-family: Verdana, sans-serif;
}
.mySlides{
    display: nonde
}
/* 幻灯片容器 */
.slideshow-container {
    max-width: 1000px;
    position: relative;
    margin: auto;
}
/* 下一张 & 上一张 按钮 */
.prev, .next{
    cursor: pointer;
    position: absolute;
    top: 50%;
    width: auto;
    margin-top: -22px;
    padding: 16px;
    color: white;
    font-size: 18px;
    transition: 0.6s ease;
    border-radius: 0 3px 3px 0;
}
/*定位  "下一张" 按钮靠右*/
.next{
    right: 0;
    border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with alittle bot see-through */
.prev:hover,
.next:hover{
    background-color: rgba(0,0,0,0.8);
}

/* 标题文本 */
.text{
    color: #f2f2f2;
    font-size: 15px;
    padding: 8px 12px;
    position: absolute;
    bottom: 8px;
    width: 100%;
    text-align: center;
}
/* 数字文本(1/3等) */
.numbertext{
    color: #f2f2f2;
    font-size: 12px;
    padding: 8px 12px;
    position: absolute;
    top: 0;
}
/* 标记符号 */
.dot{
    cursor: pointer;
    height: 13px;
    width: 13px;
    margin: 0 2px;
    background-color: #bbb;
    border-radius: 50%;
    display: inline-block;
    transition: background-color 0.6s ease;
}

.active,
.dot: hover {
    background-color: #717171;
}

/* 淡出动画 */
.fade{
    -webkit-animation-name: fade;
    -webkei-animation-duration: 1.5s;
    animation-name: fade;
    animation-duration: 1.5s;
}

@-webkit-ketframes fade {
    from {
        opacity: .4
    }

    to {
        opacity: 1
    }
}

@keyframes fade {
    from {
        opacity: .4
    }
 
     to {
        opacity: 1
    }
}

body : hover{
    cursorz: url('C:\Users\123\Pictures\LYLOGO.png'), auto
}

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以参考以下步骤来自定义一个 Vue 轮播图组件: 1. 创建一个 Vue 组件,并定义需要的属性。例如,轮播图列表、轮播图宽度、轮播时间间隔等。 ```javascript <template> <div class="carousel"> <div class="carousel-wrapper" :style="{ width: wrapperWidth + 'px' }"> <div class="carousel-content" :style="{ transform: 'translateX(' + translateX + 'px)' }"> <div v-for="(item, index) in list" :key="index" class="carousel-item" :style="{ width: itemWidth + 'px' }"> <img :src="item.src" alt=""> </div> </div> </div> </div> </template> <script> export default { name: 'Carousel', props: { list: { type: Array, default: () => [] }, interval: { type: Number, default: 3000 }, width: { type: Number, default: 600 } }, data() { return { currentIndex: 0, itemWidth: 0, wrapperWidth: 0, translateX: 0, timer: null } }, mounted() { this.init() }, methods: { init() { this.itemWidth = this.width this.wrapperWidth = this.width * this.list.length this.autoPlay() }, autoPlay() { this.timer = setInterval(() => { this.next() }, this.interval) }, next() { this.currentIndex = (this.currentIndex + 1) % this.list.length this.translateX = -this.currentIndex * this.itemWidth } } } </script> ``` 2. 在组件中实现轮播图的逻辑。例如,自动播放、手动滑动等。 3. 根据需要添加样式,使组件的 UI 更美观。 4. 在父组件中使用自定义轮播图组件。 ```javascript <template> <div> <carousel :list="list" :interval="3000" :width="600"></carousel> </div> </template> <script> import Carousel from './Carousel.vue' export default { name: 'App', components: { Carousel }, data() { return { list: [ { src: 'https://picsum.photos/600/300?random=1' }, { src: 'https://picsum.photos/600/300?random=2' }, { src: 'https://picsum.photos/600/300?random=3' } ] } } } </script> ``` 以上就是自定义 Vue 轮播图组件的基本步骤。当然,可以根据实际需要进行更多的扩展和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值