<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>10-3.觸控螢幕,或滑鼠拖曳,向左或向右滑動圖片:方法2</title>
<link rel="stylesheet" href="jquery.mobile-1.4.2/jquery.mobile-1.4.2.min.css">
<script src="jquery.mobile-1.4.2/jquery-1.9.1.min.js"></script>
<script src="jquery.mobile-1.4.2/jquery.mobile-1.4.2.min.js"></script>

<script type="text/javascript">
pagenum=0;
picnum=1;

$(document).ready(function()
{

//滑鼠按住向右滑,或觸控螢幕向右滑
$('body').bind('swiperight',function(event)
{
switch(pagenum)
{
case 0:
pages="#main";
pagenum = -1;
//設定三個頁面的圖片編號
picnum -=1;
if(picnum <=0){picnum=24;}
$('#pic0').attr({src:"picCar/car" + picnum + ".jpg"});
$('#pic1').attr({src:"picCar/car" + picnum+1 + ".jpg"});
$('#pic_1').attr({src:"picCar/car" + picnum-1 + ".jpg"});
$('#head0').html("跑車導覽:圖片 car" + picnum + ".jpg");
break;
case -1:
pages="#a_1";
pagenum =1;
//設定三個頁面的圖片編號
picnum -=1;
if(picnum <=0){picnum=24;}
$('#pic_1').attr({src:"picCar/car" + picnum + ".jpg"});
$('#pic0').attr({src:"picCar/car" + picnum+1 + ".jpg"});
$('#pic1').attr({src:"picCar/car" + picnum-1 + ".jpg"});
$('#head_1').html("跑車導覽:圖片 car" + picnum + ".jpg");
break;
case 1:
pages="#a1";
pagenum = 0;
//設定三個頁面的圖片編號
picnum -=1;
if(picnum <=0){picnum=24;}
$('#pic1').attr({src:"picCar/car" + picnum + ".jpg"});
$('#pic_1').attr({src:"picCar/car" + picnum+1 + ".jpg"});
$('#pic0').attr({src:"picCar/car" + picnum-1 + ".jpg"});
$('#head1').html("跑車導覽:圖片 car" + picnum + ".jpg");
break;

}
$.mobile.changePage(pages,{transition:'slide',reverse:true});
});
$('body').bind('swipeleft',function(event)
{
switch(pagenum)
{
case 0:
pages="#main";
pagenum =1;
//設定三個頁面的圖片編號
picnum +=1;
if(picnum > 24){picnum=1;}
$('#pic0').attr({src:"picCar/car" + picnum + ".jpg"});
$('#pic1').attr({src:"picCar/car" + picnum+1 + ".jpg"});
$('#pic_1').attr({src:"picCar/car" + picnum-1 + ".jpg"});
$('#head0').html("跑車導覽:圖片 car" + picnum + ".jpg");
break;
case 1:
pages="#a1";
pagenum = -1;
//設定三個頁面的圖片編號
picnum +=1;
if(picnum > 24){picnum=1;}
$('#pic1').attr({src:"picCar/car" + picnum + ".jpg"});
$('#pic_1').attr({src:"picCar/car" + picnum+1 + ".jpg"});
$('#pic0').attr({src:"picCar/car" + picnum-1 + ".jpg"});
$('#head1').html("跑車導覽:圖片 car" + picnum + ".jpg");
break;
case -1:
pages="#a_1";
pagenum =0;
//設定三個頁面的圖片編號
picnum +=1;
if(picnum > 24){picnum=1;}
$('#pic_1').attr({src:"picCar/car" + picnum + ".jpg"});
$('#pic0').attr({src:"picCar/car" + picnum+1 + ".jpg"});
$('#pic1').attr({src:"picCar/car" + picnum-1 + ".jpg"});
$('#head_1').html("跑車導覽:圖片 car" + picnum + ".jpg");
break;

}
$.mobile.changePage(pages,{transition:'slide',reverse:false});
});

});
</script>

</head>

<body>

<div data-role="page" id="main">
<div data-role="header">
<h1 id="head0">請觸控螢幕,或滑鼠拖曳,向左或向右滑動</h1>
</div>

<div data-role="content">
<p></p>
<img src="picCar/car1.JPG" id = "pic0" width="640" height="480">

</div>

<div data-role="footer">
<h1>世界名車大賞</h1>
</div>
</div>

<div data-role="page" id="a1">
<div data-role="header" >
<h1 id="head1">跑車導覽</h1>
</div>

<div data-role="content">
<img src="picCar/car2.JPG" id = "pic1" width="640" height="480">
</div>

<div data-role="footer">
<h1>世界名車大賞</h1>
</div>

</div>

<div data-role="page" id="a_1">
<div data-role="header" >
<h1 id="head_1">跑車導覽</h1>
</div>

<div data-role="content">
<img src="picCar/car24.JPG" id = "pic_1" width="640" height="480">

</div>

<div data-role="footer">
<h1>世界名車大賞</h1>
</div>

</div>

 

 

</body>
</html>