VUE routing component left-right swipe toggle (mobile)

Source: Internet
Author: User


<template><div id= "headed" ><ul class= "tab" ><li> <!--@click = "Jump (Index) Index: Toggle color for routed file: class= "{' Active_color ': index==0} when index equals 0 When the first one is displayed, Index:1 toggles the volleyball--><div class= "body_bottom" @click = "Jump (0)": class= "{' Active_color ': index==0} "> Basketball </div></li><li><div class=" body_bottom "@click =" Jump (1) ": class=" {' Active_color ': Index==1} "> Volleyball </div></li><li><div class=" body_bottom "@click =" Jump (2) ": class=" {' Active_ Color ': index==2} ' > Soccer </div></li></ul><div class= "line" ></div> <!--swipe Boxnum: Represents several routing components marginleft: Offset--><div:class= "{shift:ismove}": style= "{Width:boxnum * 3 + ' px ', marginleft:marginleft + ' px '} "@touchstart =" Start ($event) "@touchmove =" Move ($event) "@ Touchend= "End ($event)" > <!--ThreeWhere a routing component is placed--><introduce></introduce><agenda></agenda><member></member> </div></div></template><script>import introduce from "./introduce.vue" and "Import Agenda from". Agenda.vue "Import Member from"./member.vue "Export Default{data () {return {tabnum:1,//tab-Toggle page width (calculated from interface data) index:0, Selected tab BOXNUM:1,//Container width marginleft:0,//Offset ismove:true,//Is sliding startx:0, starty:0, movex:0, movry:0, endx:0, endy:0, m_sx:0, m_sy:0, e_sx:0, e_xy:0, Sml:0}},me Thods: {Jump (index) {this.index = Index;},start (EV) {ev.stoppropagation (); This.ismove = false; This.startx = Ev.changedtouches[0].clientx; This.starty = Ev.changedtouches[0].clienty; THIS.SML = This.marginleft; }, Move (EV) {ev.stoppropagation (); This.movex = ev.changedtouches[0].clientx; This.movey = Ev.changedtouches[0].clienty; THIS.M_SX = This.movex-this.startx; This.m_sy = This.movey-this.starty; var marginleft = this.sml + this.m_sx; MarginLeft = marginleft > 0? 0:marginleft; MarginLeft = MarginLeft < 360-this.boxnum * 360? 360-this.boxnum * 360:MARGINLEFT; This.marginleft = MarginLeft; }, End (EV) {this.ismove = true; if (Math.Abs (THIS.M_SX) > Math.Abs (this.m_sy) && math.abs (THIS.M_SX) > $) {var multiple = THIS.M_SX > 0? -1:1; var index = this.index + multiple; index = Index < 0? 0:index; index = index > this.boxnum-1? This.boxnum-1: Index; This.index = index; } else {this.marginleft = 0-this.index * 360; }}},mounted () {//Number of routing components This.boxnum = 3;},components: {//Component name Introduce, Agenda, Member}, watch: {index:function (newvalue, OldValue) { This.marginleft = 0-this.index * 360; }}}</script><style scoped= "scoped" > #headed {width:360px;overflow:hidden;}. Line{width:100%;height:1px;background-color: #e6e6e6; margin-top: -2px;}. tab{overflow:hidden;padding:0;margin:0;height:45px;line-height:45px;}. tab Li{float:left;list-style:none;width:33.3%;text-align:center;}. body_bottom{width:30px;height:42px; margin:0 Auto; Text-align:center; font-size:13px;}. Active_color{color: #d22330; border-bottom:2px solid #d22330!important;}. shift {Transition-property:margin-left; Transition-duration:1s; }</style>

、

Detailed GitHub Address: Https://github.com/CrazyProgrammer12138/routerslider

VUE routing component left-right swipe toggle (mobile)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.