Home > Web Front-end > JS Tutorial > jquery mobile terminal TAB touch screen switching effect_jquery

jquery mobile terminal TAB touch screen switching effect_jquery

WBOY
Release: 2016-05-16 15:34:51
Original
1690 people have browsed it

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.

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="#">CSS3</a></li> 
   <li><a href="#">JAVASCRIPT</a></li> 
  <li><a href="#">PHP</a></li> 
  <li><a href="#">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. This should be set according to our own habits and hobbies.

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 is the key code about the TAB touch screen switching effect on the mobile terminal. I hope you like it.

Related labels:
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