美文网首页
Vue基础实现无缝手动轮播图

Vue基础实现无缝手动轮播图

作者: 似朝朝我心 | 来源:发表于2020-09-22 22:05 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        font-weight: bolder;
        font-size: 40px;
    }
    
    img {
        height: 400px;
        width: 600px;
    }
    body {
        background-color: black;
    }
    .container {
        width: 600px;
        height: 400px;
        margin: 80px auto;
        border: 5px solid #eeeeee;
        border-radius: 8px;
        box-shadow: 10px 10px 400px #0a8a9b;
        
    }
    button {
        outline-style: none;
        width: 50px;
        border-radius: 50%;
        opacity:0.5;
        filter:Alpha(opacity=50);
        cursor: pointer;
    }
    button:hover {
        
        box-shadow: 0 -1px 60px red; 
        opacity:1;
        filter:Alpha(opacity=100);
    }
    .right-box {
        position: relative;
        left: 465px;
        
    }
    .arrow-move {
        margin-top: -250px;
        padding: 10px;
        
    }
    .index-box {
        margin: -150px 0px;
    }
    .index-box ul li:nth-child(1) {
    color: #000;
    }
   ul li {
        color: white;
        height: 16px; 
        width: 16px;
        padding: 10px;
       

    }
    li:hover {
        color: black;
        cursor: pointer;

    }
</style>
<body>
    <div id="app">
        <div class="container">
        <img :src="images[index]">
        <!--
        简单实现,不需要通过定义方法 
        <button @click="index--"> < </button>
        <button @click="index++"> > </button> 
        -->
        <div class="arrow-move">
        <button class="left-box" @click="backward"> < </button>
        <button class="right-box" @click="forward"> > </button>
        </div>
        
        <div class="index-box">
        <ul>
            <li v-for="img in images" :key="img"></li>
        </ul>
        </div>   
        
    </div>       
    </div>
<script>
    const app = new Vue({
    el: '#app',
    data () {
        return {  
            index: 0,
            images: [
                './images/img1.jpg',
                './images/img2.jpg',
                './images/img3.jpg',
                './images/img4.jpg',
                './images/img5.jpg'
            ]
        }
    },
    methods: {
        
        forward () {   
            let timer = setTimeout(() => {
                this.index++;                       
            if (this.index == this.images.length) {
               this.index = 0;            
            }
            }, 400);
        },
        backward () {
            let timer = setTimeout(() => {
                this.index--; 
            if (this.index < 0) {
                this.index = this.images.length - 1;
            }
            }, 400);
        },
        
    }
})
</script>
</body>
</html>

不完美的地方,页码器追踪(就是页码器和轮播图双向互动),那块没做,逻辑太绕了。

相关文章

  • Vue基础实现无缝手动轮播图

    不完美的地方,页码器追踪(就是页码器和轮播图双向互动),那块没做,逻辑太绕了。

  • jQuery可任意修改轮播图大小的无缝轮播图

    这个无缝轮播图比之前而言,加入了可随意在CSS样式中修改轮播图大小,JS中无需手动修改。 css样式: html代...

  • 用appendChild方法实现无缝轮播图(附详细注释)

    轮播图非常常见,今天就介绍怎样用appendChild以及translateX实现无缝轮播图。 以5张图,每张图宽...

  • Vue 无缝轮播实现

    实现原理: 1.采用css3 实现 滚动效果(过渡动画) 2.采用 dom 事件监听 监听 过度动画 3.无缝原理...

  • Vue 实现无缝轮播

    很多网站都会有轮播图的需求,而简单的轮播图实现通常会在展示完最后一个子项后停止轮播,或者跳回到第一个子项重复轮播过...

  • VUE 脚手架项目中轮播图的实现

    VUE项目中轮播图的实现 vue-awesome-swiper ——依赖插件vue-awesome-swiper...

  • 无标题文章

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。它们各具特色,各有用处。 1.传统轮播图 第一步...

  • 轮播图

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。 1.传统轮播图 第一步,得到元素 第二步,设置...

  • 三种样式的轮播图

    一、100%比例轮播图 HTML代码 CSS样式 js代码 二、手动箭头轮播图 三、简易轮播图

  • JS中常见的几种轮播

    轮播图 1.无缝不停轮播 ​ 1. body布局: ​ 2. css样式: 3. JS代码: 2.无缝停顿...

网友评论

      本文标题:Vue基础实现无缝手动轮播图

      本文链接:https://www.haomeiwen.com/subject/rkmgyktx.html