_javascript technique of Mobile End tab touch screen switching effect based on JavaScript

Source: Internet
Author: User

The display effect diagram looks like this:

Effect Demo Source Download

We use the mobile end can be touched by the touch screen gesture left and right to switch tab column, such as NetEase news, such as app column switch. We say that the tab generally by the navigation bar and the corresponding content of the tab, switch the navigation bar on the label at the same time the content will follow the switch. This article will be combined with examples to introduce a mobile End tab touch Switch effect.

Html

We prepare a tab navigation #pagenavi, which contains tab navigation to switch the four navigation buttons, and then the main content of the switch #slider, here should be placed four Li and navigation buttons corresponding, content customization.

<div class= "Box-163css" > 
  <ul id= "Pagenavi" class= "page" > 
    <li><a href= "#http:// Www.jb51.net/css.html "class=" active ">CSS3</a></li> 
     <li><a href=" #http:// Www.jb51.net/jquery.html ">JAVASCRIPT</a></li> 
    <li><a href=" #http://www.jb51.net/ Php.html ">PHP</a></li> 
    <li><a href=" #http://www.jb51.net/web.html ">html5</a ></li> 
  </ul> 
  <div id= "slider" class= "swipe" > 
   <ul class= "Box01_list" > 
    <li class= "Li_list" > ... 
    </li> 
    ...<!--Total 4 li--> 
   </ul> 
  </div> 
</div>

Of course, we also need to add CSS style to HTML, this example has packaged CSS files for everyone to download.

Javascript

Because it is the mobile end of the application, we load zepto.js,zepto is small size jquery. Then you need to load the touch-screen slide plugin touchslider.js.

<script type= "Text/javascript" src= "js/zepto_min.js" ></script> 
<script type= "Text/javascript" Src= "Js/touchslider.js" ></script>

Next we directly call Touchslider, by setting the Binding tab, slide direction, speed, time and other information to achieve the content switch, please see detailed code:

<script type= "Text/javascript" > var page= ' Pagenavi '; 
  var mslide= ' slider '; 
  var mtitle= ' Emtitle '; 
  Arrdiv = ' Arrdiv '; 
  var As=document.getelementbyid (page). getElementsByTagName (' a '); var tt=new touchslider ({id:mslide, ' auto ': '-1 ', FX: ' Ease-out ', direction: ' Left ', speed:600,timeout:5000, ' before ': 
    function (index) {var As=document.getelementbyid (this.page). getElementsByTagName (' a '); 
    As[this.p].classname= '; 
    As[index].classname= ' active '; 
    This.p=index; 
    var Txt=as[index].innertext; 
    $ ("#" +this.page). Parent (). Find ('. Emtitle '). Text (TXT);     
    var txturl=as[index].getattribute (' href '); 
    var turl=txturl.split (' # '); 
  $ ("#" +this.page). Parent (). Find ('. go_btn '). attr (' href ', turl[1]); 
  }}); 
  tt.page = page; 
  TT.P = 0; 
      for (Var i=0;i<as.length;i++) {(function () {var j=i; 
      AS[J].TT = TT; 
        As[j].onclick=function () {this.tt.slide (j); 
      return false; 
  } 
    })(); } </script>

The above content is the entire description of this article, I hope to help you learn.

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.