我剛開始也在找這個(gè)問題的答案,現(xiàn)在解決了,為后面學(xué)習(xí)的人栽棵樹吧。

梅河口ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!
實(shí)現(xiàn)這個(gè)功能有很多種方法,這里我選一種個(gè)人認(rèn)為比較簡單的方法:
建立三個(gè)網(wǎng)頁,一個(gè)作為主頁面,另外兩個(gè)子頁面作為切換頁面嵌入主頁面,子頁面也可以用文字替代。
用jQuery方法來切換頁面,語言比較簡單網(wǎng)上搜一下看看就懂了
下面附上代碼
!DOCTYPE?html
html
head
meta?charset="UTF-8"
title標(biāo)題/title
!--jQuery?百度CDN庫--
script?src=""/script
script
//?jQuery代碼
$(document).ready(function?()?{
$("#b1").click(function?()?{
$("#tab_1").show();//?顯示
$("#tab_2").hide();//?隱藏
});
$("#b2").click(function?()?{
$("#tab_1").hide();
$("#tab_2").show();
});
});
/script
/head
body
div
h1標(biāo)題一/h1
/div
div
div
ul
libutton?id="b1"菜單1/button/li
libutton?id="b2"菜單2/button/li
/ul
/div
div
div?id="tab_1"
子頁面1
/div
div?id="tab_2"?style="display:?none"
子頁面2
/div
/div
/div
/body
/html
左右滑動和上下滑動都是交互的形式,使用哪一種主要看應(yīng)用的具體場景。
當(dāng)然,也有一些需要普遍注意的地方,如:
1、蘋果手機(jī)上,向右滑動容易觸發(fā)返回上一級頁面。所以為了交互體驗(yàn),要慎用向右滑動的操作方式。
2、設(shè)置向上滑動翻頁時(shí),指引箭頭應(yīng)該向上而不是向下;如果是點(diǎn)擊翻頁,則用向下的箭頭。
3、功能按鈕等盡量遠(yuǎn)離頁面的底部,以便更好地適配各種類型、各種大小的手機(jī),防止按鈕被擋住。
我們使用移動端時(shí)可以通過觸屏手勢左右滑動來切換TAB欄目,我們說的TAB一般由導(dǎo)航條和TAB對應(yīng)的內(nèi)容組成,切換導(dǎo)航條上的標(biāo)簽同時(shí)標(biāo)簽對應(yīng)的內(nèi)容也會跟著切換。
我們準(zhǔn)備一個(gè)TAB導(dǎo)航#pagenavi,里面包含TAB導(dǎo)航要切換的四個(gè)導(dǎo)航按鈕,然后是切換的主體內(nèi)容#slider,這里應(yīng)該放置四個(gè)li與導(dǎo)航按鈕對應(yīng),內(nèi)容自定義。
由于是移動端應(yīng)用,我們加載zepto.js,zepto就是體積小的jquery。然后需要加載觸屏滑動插件touchslider.js。
接下來我們就直接調(diào)用TouchSlider,通過設(shè)置綁定tab,滑動方向、速度、時(shí)間等信息實(shí)現(xiàn)內(nèi)容切換,請看詳細(xì)代碼:
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;ias.length;i++){
(function(){
var j=i;
as[j].tt = tt;
as[j].onclick=function(){
this.tt.slide(j);
return false;
}
})();
}
/script
HTML5手機(jī)上下滑動翻頁特效是一款手機(jī)移動端觸屏滑動效果實(shí)現(xiàn)完整代碼如下:
1、html5頁面代碼
!DOCTYPE html
htmlheadmeta http-equiv="Content-Type" content="text/html; charset=UTF-8"
titleHTML5手機(jī)頁面觸屏滑動上下翻頁特效/title
meta charset="utf-8"
meta name="apple-touch-fullscreen" content="YES"
meta name="format-detection" content="telephone=no"
meta name="apple-mobile-web-app-capable" content="yes"
meta name="apple-mobile-web-app-status-bar-style" content="black"
meta http-equiv="Expires" content="-1"
meta http-equiv="pragram" content="no-cache"
link rel="stylesheet" type="text/css" href="./hamer_files/main.css"
link rel="stylesheet" type="text/css" href="./hamer_files/endpic.css"
script type="text/javascript" src="./hamer_files/offline.js"/script
meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi"
/head
body class="s-bg-ddd pc no-3d perspective yes-3d" style="-webkit-user-select: none;"
section class="u-alert"
? img style="display:none;" src="./hamer_files/loading_large.gif"
? div class="alert-loading z-move"
? ? ? div class="cycleWrap" span class="cycle cycle-1"/span
? ? ? ? ? span class="cycle cycle-2"/spanspan class="cycle cycle-3"/spanspan class="cycle cycle-4"/span
? ? ? /div
? ? ? div class="lineWrap" span class="line line-1"/spanspan class="line line-2"/spanspan class="line line-3"/span
? ? ? /div
? /div
/section
section class="u-arrow"
? p class="css_sprite01"/p
/section
section class="p-ct transformNode-2d transformNode-3d" style="height: 918px;"
? div class="translate-back" style="height: 918px;"
? ? ? div class="m-page m-fengye" data-page-type="info_pic3" data-statics="info_pic3" style="height: 918px;"
? ? ? ? ? div class="page-con lazy-finish" data-position="50% 50%" data-size="cover" style="height: 920px; background-image: url(hamer_files/1.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/2.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/3.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/4.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/5.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/6.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/7.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/8.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? /div
/section
section class="u-pageLoading"
? img src="./hamer_files/load.gif" alt="loading"
/section
script src="./hamer_files/init.mix.js" type="text/javascript" charset="utf-8"/script
script src="./hamer_files/coffee.js" type="text/javascript" charset="utf-8"/script
script src="./hamer_files/99_main.js" type="text/javascript" charset="utf-8"/script
/body/html
2、css代碼:
@charset "utf-8";
.ad_foot li { margin:0 auto 1em; font-size:1.8em; padding:15px; background:#FFF;}
.ad_foot li a {display:block;}
.ad_foot li .l {width:75px; height:75px; float:left; overflow:hidden;}
.ad_foot li .l img {width:75px; width:75px;}
.ad_foot li .r {width:78%; float:left; margin-left:30px; color:#666; overflow:hidden;}
.ad_foot li .r p {color:#999; font-size:1.2em; }
.ad_foot li .r span {font-size:0.8em;}
.ad_foot li .r i {font-style:normal;}
.lazy-img, .lazy-finish{background-color:#f0eded;}
.page-list{font-size:20px;font-family: "Microsoft yahei";padding-left:17px;padding-top:30px;height:35px;border-bottom:1px solid #b5b5b5;display:none;}
.ad_foot{padding:15px 15px 0 15px;}
/*聲音播放按鈕*/
#song_img {width:293px; height:41px; display:block; position:absolute; right:4.1em; top:1.6em; font-size:1.7em; text-align:center; line-height:41px; color:#FFF; background:url(../img/music_c3.png) no-repeat 0 0;}
/*底部推薦*/
.ad_list{margin-top:2em;}.ad_list li {width:46%; background:none; padding:0; float:left;margin-bottom: 1em;}
.ad_list li.r {float:right;}.ad_list li a img {width:100%; height:auto;}
.ad_foot h3 {width:100%; height:48px; line-height:48px; background:#F9F5EC;}
.ad_foot h3 a {display:inline-block; color:#444; width:50%; text-align:center; font-size:1.5em; height:48px; border-bottom:2px solid #FF9240;}
.ad_foot h3 a.active {color:#FFF; background:#FF9240;}
.magazine_1 li {
width:100%;
margin-bottom: 1em;
font-size: 1.8em;
padding: 15px;
background: #FFF;}
.magazine_1 li a {display:block;}
.magazine_1 li .l {width: 75px;
height: 75px;
float: left;
overflow: hidden;}
.magazine_1 li .l img {width:75px; height:75px;}
.magazine_1 li .r {width: 78%;
float: left;
margin-left: 30px;
color: #666;
overflow: hidden;}
.magazine_1 li .r p {
color: #999;
font-size: 1.2em;
.magazine_1 li .r span {font-size:0.8em;}
.ad_foot li .r i {font-style:normal;}
3、運(yùn)行效果如下:
左右滑動是由觸摸事件定義的,觸摸事件(touch)會在用戶手指放在屏幕上面的時(shí)候、在屏幕上滑動的時(shí)候或者是從屏幕上移開的時(shí)候觸發(fā)。下面具體說明:
touchstart事件:當(dāng)手指觸摸屏幕時(shí)候觸發(fā),即使已經(jīng)有一個(gè)手指放在屏幕上也會觸發(fā)。
touchmove事件:當(dāng)手指在屏幕上滑動的時(shí)候連續(xù)地觸發(fā)。在這個(gè)事件發(fā)生期間,調(diào)用preventDefault()事件可以阻止?jié)L動。
touchend事件:當(dāng)手指從屏幕上離開的時(shí)候觸發(fā)。
touchcancel事件:當(dāng)系統(tǒng)停止跟蹤觸摸的時(shí)候觸發(fā)。關(guān)于這個(gè)事件的確切出發(fā)時(shí)間,文檔中并沒有具體說明,咱們只能去猜測了。
上面的這些事件都會冒泡,也都可以取消。雖然這些觸摸事件沒有在DOM規(guī)范中定義,但是它們卻是以兼容DOM的方式實(shí)現(xiàn)的。所以,每個(gè)觸摸事件的event對象都提供了在鼠標(biāo)實(shí)踐中常見的屬性:bubbles(起泡事件的類型)、cancelable(是否用 preventDefault() 方法可以取消與事件關(guān)聯(lián)的默認(rèn)動作)、clientX(返回當(dāng)事件被觸發(fā)時(shí),鼠標(biāo)指針的水平坐標(biāo))、clientY(返回當(dāng)事件觸發(fā)時(shí),鼠標(biāo)指針的垂直坐標(biāo))、screenX(當(dāng)某個(gè)事件被觸發(fā)時(shí),鼠標(biāo)指針的水平坐標(biāo))和screenY(返回當(dāng)某個(gè)事件被觸發(fā)時(shí),鼠標(biāo)指針的垂直坐標(biāo))。除了常見的DOM屬性,觸摸事件還包含下面三個(gè)用于跟蹤觸摸的屬性。
touches:表示當(dāng)前跟蹤的觸摸操作的touch對象的數(shù)組。
targetTouches:特定于事件目標(biāo)的Touch對象的數(shù)組。
changeTouches:表示自上次觸摸以來發(fā)生了什么改變的Touch對象的數(shù)組。
每個(gè)Touch對象包含的屬性如下。
clientX:觸摸目標(biāo)在視口中的x坐標(biāo)。
clientY:觸摸目標(biāo)在視口中的y坐標(biāo)。
identifier:標(biāo)識觸摸的唯一ID。
pageX:觸摸目標(biāo)在頁面中的x坐標(biāo)。
pageY:觸摸目標(biāo)在頁面中的y坐標(biāo)。
screenX:觸摸目標(biāo)在屏幕中的x坐標(biāo)。
screenY:觸摸目標(biāo)在屏幕中的y坐標(biāo)。
target:觸目的DOM節(jié)點(diǎn)目標(biāo)。
舉個(gè)例子-JavaScript代碼:
function?load?(){
document.addEventListener('touchstart',touch,?false);
document.addEventListener('touchmove',touch,?false);
document.addEventListener('touchend',touch,?false);
function?touch?(event){
var?event?=?event?||?window.event;
var?oInp?=?document.getElementById("inp");
switch(event.type){
case?"touchstart":
oInp.innerHTML?=?"Touch?started?("?+?event.touches[0].clientX?+?","?+?event.touches[0].clientY?+?")";
break;
case?"touchend":
oInp.innerHTML?=?"brTouch?end?("?+?event.changedTouches[0].clientX?+?","?+?event.changedTouches[0].clientY?+?")";
break;
case?"touchmove":
event.preventDefault();
oInp.innerHTML?=?"brTouch?moved?("?+?event.touches[0].clientX?+?","?+?event.touches[0].clientY?+?")";
break;
}
}
}
window.addEventListener('load',load,?false);
HTML代碼:
div?id="inp"/div
上面的小例子當(dāng)touchstart事件觸發(fā)的時(shí)候,會將觸摸的位置更新到div標(biāo)簽中。當(dāng)touchmove事件觸發(fā)的時(shí)候,會默認(rèn)行為的滾動
(觸摸移動的默認(rèn)行為是滾動頁面),然后觸摸操作的變化信息更新到div標(biāo)簽中。而touchend事件會輸出有關(guān)觸摸操作的最終信息。注意,在
touchend事件觸發(fā)的時(shí)候,touches集合中就沒有任何Touch對象了,因?yàn)椴淮嬖诨顒拥挠|摸操作。
這些事件會在文檔的所有元素上面觸發(fā),因而可以分別操作頁面的不同部分。在觸摸屏幕上的元素,這些事件(包括鼠標(biāo)事件)發(fā)生的順序如下:
(1)touchstart
(2)mouseover
(3)mousemove(一次)
(4)mousedown
(5)mouseup
(6)click
(7)touchend
普通banner或信息列表可以用IScroll上下左右均可滑動
頁面滑動切換的話建議使用jquery mobile,實(shí)現(xiàn)如下事件,進(jìn)行changepage
swipe(劃動):一秒內(nèi)水平拖拽大于30PX,同時(shí)縱向拖曳小?0px的事件發(fā)生時(shí)觸發(fā)
swipeleft(左劃):劃動事件為向左的方向時(shí)觸發(fā)
swiperight(右劃):劃動事件為向右的方向時(shí)觸發(fā)
分享題目:html5滑動頁面切換,html5左右滑動頁面
文章源于:http://chinadenli.net/article29/dsggich.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、面包屑導(dǎo)航、Google、用戶體驗(yàn)、做網(wǎng)站、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)