IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> JavaScript知识库 -> Vue+js 实现左右拖动 -> 正文阅读

[JavaScript知识库]Vue+js 实现左右拖动

<div class="wrap-4">
        <div class="wrap-4-card" v-on:touchstart="bannerTouchStart" v-on:touchend="bannerTouchEnd($event)" v-on:touchcancel="bannerTouchEnd($event)">
            <ul class="contentBox">
                <li class="wrap-4-pic wrap-4-pic1"></li>
                <li class="wrap-4-pic wrap-4-pic2"></li>
                <li class="wrap-4-pic wrap-4-pic3"></li>
            </ul>
        </div>
        <div class="circle-card">
            <div class="circle-item" :class="{'active':focusBannerIndex == 0}"></div>
            <div class="circle-item" :class="{'active':focusBannerIndex == 1}"></div>
            <div class="circle-item" :class="{'active':focusBannerIndex == 2}"></div>
        </div>
        <div class="wrap-button" @click="btnClick('点击咨询详情')">点击咨询详情</div>
    </div>
.wrap-4{
        height: 1365px;
        background: url($imageUrl + 'wrap-4.png') no-repeat center;
        background-size: cover;
        overflow: hidden;
        .wrap-4-card{
            position: absolute;
            left: 0;
            bottom: 226px;
            padding-left: 79px;
            box-sizing: border-box;
            font-size: 0;
            width: 100%;
            overflow: auto;
            ul{
                width: 1892px;
            }
            li{
                display: inline-block;
                width: 621px;
                height: 719px;
            }
            .wrap-4-pic1{
                background: url($imageUrl + 'wrap-4-pic1.png') no-repeat left center;
                background-size: 571px 100%;
            }
            .wrap-4-pic2{
                background: url($imageUrl + 'wrap-4-pic2.png') no-repeat left center;
                background-size: 571px 100%;
            }
            .wrap-4-pic3{
                background: url($imageUrl + 'wrap-4-pic3.png') no-repeat left center;
                background-size: 571px 100%;
            }
        }
        .circle-card{
            bottom: px;
            font-size: 0;
            text-align: center;
            .circle-item{
                display: inline-block;
                width: 12px;
                height: 12px;
                background: #C9CACC;
                border-radius: 50%;
                margin-right: 15px;
                &:last-child{
                    margin-right: 0;
                }
                &.active{
                    background: #FF8219;
                }
            }
        }
    }
Vue({
    el:"#intelligentHomework",
    data:{
        focusBannerIndex : 0,
        bannerList: 3,
    },
    computed: {
    },
    components: {},
    methods:{
        bannerMove(arrow){
            let vm = this;
            let focusBannerIndex = vm.focusBannerIndex;
            let bannerLen = vm.bannerList;
            let nextBannerIndex = vm.nextBannerIndex;
            if(bannerLen <= 1){
                return false;
            }
            switch (arrow) {
                case "right":
                    //向右滑动
                    nextBannerIndex = focusBannerIndex + 1 >= bannerLen ? bannerLen-1 : focusBannerIndex + 1;
                    break;
                case "left":
                    //向左滑动
                    nextBannerIndex = focusBannerIndex - 1 < 0 ? 0 : focusBannerIndex - 1;
                    break;
                default:
                    nextBannerIndex = 0;
            }
            vm.focusBannerIndex = nextBannerIndex;
            let scrollNumber = (nextBannerIndex*$('.wrap-4-pic').width())+'px';
            $('.wrap-4-card').animate({ 'scrollLeft': scrollNumber}, 200);
        },
        bannerTouchStart(e){
            let vm = this;
            e.preventDefault();
            vm.startPointY = (e.clientY || e.changedTouches[0].clientY);
            vm.startPointX = (e.clientX || e.changedTouches[0].clientX);
        },
        bannerTouchEnd(e){
            e.preventDefault();
            let vm = this;
            let startPointY = vm.startPointY;
            let startPointX = vm.startPointX;
            let endPointY = (e.clientY || e.changedTouches[0].clientY);
            let endPointX = (e.clientX || e.changedTouches[0].clientX);
            if(Math.abs(endPointY - startPointY)>Math.abs(endPointX - startPointX) || Math.abs(endPointX - startPointX) < 20){
                //认为没有滑动
                return false;
            }
            vm.bannerMove((endPointX > startPointX) ? "left":"right");
        },
    },
    created(){
    },
    mounted(){
    }
})
  JavaScript知识库 最新文章
ES6的相关知识点
react 函数式组件 & react其他一些总结
Vue基础超详细
前端JS也可以连点成线(Vue中运用 AntVG6)
Vue事件处理的基本使用
Vue后台项目的记录 (一)
前后端分离vue跨域,devServer配置proxy代理
TypeScript
初识vuex
vue项目安装包指令收集
上一篇文章      下一篇文章      查看所有文章
加:2021-11-17 12:40:06  更:2021-11-17 12:42:35 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/10 4:38:30-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码