如何用js做翻页效果

JavaScript014

如何用js做翻页效果,第1张

参考代码如下:

<!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>