Home > Web Front-end > JS Tutorial > Implementing mobile terminal TAB touch screen switching effect based on JavaScript_javascript skills

Implementing mobile terminal TAB touch screen switching effect based on JavaScript_javascript skills

WBOY
Release: 2016-05-16 15:35:50
Original
1737 people have browsed it

The display rendering is as follows:

Effect demonstration Source code download

When we use the mobile terminal, we can use touch screen gestures to slide left and right to switch TAB columns, such as switching between APP columns such as NetEase News. The TAB we are talking about generally consists of a navigation bar and the content corresponding to the TAB. When the label on the navigation bar is switched, the content corresponding to the label will also switch accordingly. This article will introduce you to a mobile terminal TAB touch screen switching effect based on examples.

HTML

We prepare a TAB navigation #pagenavi, which contains the four navigation buttons to be switched in the TAB navigation, and then the main content of the switch #slider. Four li should be placed here to correspond to the navigation buttons, and the content is customized.

<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> 
    ...<!--总共4个li--> 
   </ul> 
  </div> 
</div>
Copy after login

Of course, we also need to add css styles to the HTML. In this example, the css files have been packaged for everyone to download.

JAVASCRIPT

Since it is a mobile application, we load zepto.js, zepto is jquery with a small size. Then you need to load the touch screen sliding plug-in toucheslider.js.

<script type="text/javascript" src="js/zepto_min.js"></script> 
<script type="text/javascript" src="js/touchslider.js"></script>
Copy after login

Next we will directly call TouchSlider to achieve content switching by setting the binding tab, sliding direction, speed, time and other information. Please see the 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>
Copy after login

The above content is the entire description of this article. I hope it will be helpful to everyone's study.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template