参考代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script type="text/javascript" language="javascript" src="http://www.codefans.net/ajaxjs/jquery-1.4.2.min.js"></script>
<script type="text/javascript" language="javascript">
$(function() {
$("#right").click(function() {
var roll = $("<div></div>", { css: { position: "absolute", border: "solid 1px #999", left: "806px", top: "10px", height: "494px", width: "1px", background: "#fff"}}).appendTo($("#book").parent())
$(roll).animate({
left: "10px",
width: "398px"
}, 1000, function() {
$("#left").css({"background":"#fff"})
$(roll).fadeOut(300, function() {
$(roll).remove()
})
})
})
})
</script>
</head>
<body style="padding:5pxmargin:0">
<div id="book" style="width:797pxheight:494pxbackground:#cccborder:solid 6px #ccc">
<div id="left" style="width:398pxheight:494pxfloat:leftbackground:url(http://www.codefans.net/jscss/demoimg/201011/PLh.png) no-repeat top leftcursor:pointer"></div>
<div id="right" style="width:398pxheight:494pxfloat:leftbackground:#fffcursor:pointermargin-left:1pxtext-align:right"><p style="margin-top:470pxfont-size:12pxcolor:#999">点这翻页 </p></div>
</div>
</body>
</html>
思路:页面中放一个隐藏变量记录当前的页面序号,下一页就是取出当前号+1,上一页就取出当前号-1<html>
<head>
</head>
<body>
paper78-01-01.htm
<input type="hidden" name="pagenumber" value="01">
<a href="javascript:goPrevious()">上一页<a/><a href="javascript:goNext()">下一页<a/>
<script type="text/javascript">
//下一页
function goNext(){
goPage(parseInt(document.all.item("pagenumber").value)+1)
}
//上一页
function goPrevious(){
goPage(parseInt(document.all.item("pagenumber").value)-1)
}
//进入页号为pageNumber的页面
function goPage(pagenumber){
if(pagenumber<1) {alert("到了首页")return}
if(pagenumber>3) {alert("到了第三页了")return}
if(pagenumber<10) pagenumber = "0"+pagenumber
window.location.href="paper78-01-"+pagenumber+".htm"
}
</script>
</body>
<html>
//html5 新增 touch 事件//禁用手机默认的触屏滚动行为
document.addEventListener('touchmove', function(event) {
event.preventDefault()
}, false)
//touchstart事件
function touchSatrtFunc(evt) {
try {
//evt.preventDefault() //阻止触摸时浏览器的缩放、滚动条滚动等
var touch = evt.touches[0] //获取第一个触点
var x = Number(touch.pageX) //页面触点X坐标
var y = Number(touch.pageY) //页面触点Y坐标
//记录触点初始位置
startX = x
startY = y
} catch (e) {
alert('touchSatrtFunc:' + e.message)
}
}
//touchmove事件,这个事件无法获取坐标
function touchMoveFunc(evt) {
try {
//evt.preventDefault() //阻止触摸时浏览器的缩放、滚动条滚动等
var touch = evt.touches[0] //获取第一个触点
var x = Number(touch.pageX) //页面触点X坐标
var y = Number(touch.pageY) //页面触点Y坐标
//document.getElementById("version").innerHTML = "原:"+startY+" "+"现:"+y
//判断滑动方向
if (y - startY > 100) {
swipeDown()
} else if(y - startY < -100){
swipeUp()
}
} catch (e) {
alert('touchMoveFunc:' + e.message)
}
}
//touchend事件
function touchEndFunc(evt) {
try {
//evt.preventDefault() //阻止触摸时浏览器的缩放、滚动条滚动等
} catch (e) {
alert('touchEndFunc:' + e.message)
}
}
//绑定事件
function bindEvent() {
document.addEventListener('touchstart', touchSatrtFunc, false)
document.addEventListener('touchmove', touchMoveFunc, false)
document.addEventListener('touchend', touchEndFunc, false)
}
//判断是否支持触摸事件
function isTouchDevice() {
//document.getElementById("version").innerHTML = navigator.appVersion
try {
document.createEvent("TouchEvent")
//alert("支持TouchEvent事件!")
bindEvent() //绑定事件
} catch (e) {
alert("不支持TouchEvent事件!" + e.message)
}
}