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.
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= "#/css.html" class= "active" >CSS3</a></li>
<li><a href= "#http://www.helloweba.net/jquery.html" >JAVASCRIPT</a></li>
<li><a href= "#/php.html" >PHP</a></li>
<li><a href= "#http://www.helloweba.net/web.html" >HTML5</a></li>
</ul>
<div id= "Slider" class= "swipe" >
<ul class= "Box01_list" >
<li class= "Li_list" >
...
</li>
...<!--A total of 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.
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>