`
mengxing0929
  • 浏览: 6295 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

滚动div,实现动态页面切换功能,实现图书翻页

阅读更多
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery-1.7.2.js" type="text/javascript" ></script>
<title>动态滚动div(实现书本翻页功能)</title>
<style type="text/css">
<!--
.scroll {
width:920px;
overflow:hidden;
}
.scrollLeft {
width:1920px;
height:450px;
margin:0px;
padding:0px;
clear:both;
position:relative;
overflow:hidden;
}
.scrollLeft img {
width:960px;
height:450px;
border:#CCCCCC solid 1px;
}
.scrollLeft .chapter {
float:left;
width:960px;
height:450px;
overflow:hidden;
}
.scrollLeft .right {
float:left;
width:960px;
height:450px;
overflow:hidden;
}

.scrollLeft .left {
float:left;
width:960px;
height:450px;
overflow:hidden;
}

-->
</style>
</head>
<body>
<div style="width:960px;position:relative;background-color:rgb(255, 255, 255);overflow:hidden;">
<div class="scrollLeft" id="scrollLeft">
<div class="chapter" id="chapter_1" style="margin-left:0px;"><a href="#"><img src="css/img/chapter_0.jpg" align="图片"/></a></div>
</div>
</div>
<div align="center" style="width:960px;">
<input type="button" id="left" value="left" onclick='RollAround.prev();'/>
<input type="button" id="right" value="right"  onclick='RollAround.next();'/>
</div>
<script>
<!--
var currentPageNo = 1;
var intervalId;
var RollAround = {
speedTime : 10,
refreshPX : 20,
maxPX : 0,
marqueeleft : function(){
var currentchapter = $("#chapter_"+currentPageNo);
if(RollAround.maxPX==0){
$("#left").attr("disabled", true);
$("#right").attr("disabled", true);
getPage('left').insertAfter(currentchapter);
}
if(RollAround.maxPX == 960){
clearInterval(intervalId);
$("#chapter_"+(currentPageNo)).remove();
currentPageNo++;
$("#left").attr("disabled", false);
$("#right").attr("disabled", false);
}else{
RollAround.maxPX += RollAround.refreshPX;

var margin = (getPxNumber(currentchapter.css("margin-left")) - RollAround.refreshPX) + "px";
currentchapter.css("margin-left", margin);

//283295058
var nextchapter = $("#chapter_"+ (currentPageNo+1));
var next_margin = (getPxNumber(nextchapter.css("margin-left")) - RollAround.refreshPX) + "px";
nextchapter.css("margin-left", next_margin);
}
},
marqueeright : function(){
var currentchapter = $("#chapter_"+currentPageNo);
if(RollAround.maxPX==0){
getPage('right').insertBefore(currentchapter);
$("#left").attr("disabled", true);
$("#right").attr("disabled", true);
}
if(RollAround.maxPX == 960){
clearInterval(this.intervalId);
$("#chapter_" + currentPageNo).remove();
currentPageNo--;
$("#left").attr("disabled", false);
$("#right").attr("disabled", false);
}else{
RollAround.maxPX += RollAround.refreshPX;

var margin = (getPxNumber(currentchapter.css("margin-left")) + RollAround.refreshPX) + "px";
currentchapter.css("margin-left", margin);

//283295058
var nextchapter = $("#chapter_" + (currentPageNo-1));
var next_margin = (getPxNumber(nextchapter.css("margin-left")) + RollAround.refreshPX) + "px";
nextchapter.css("margin-left", next_margin);
}
},
prev : function(){
RollAround.marqueetype = "left";
RollAround.maxPX = 0;
//开始循环
intervalId =setInterval(RollAround.marqueeleft, RollAround.speedTime);
},
next : function(){
RollAround.marqueetype = "right";
RollAround.maxPX = 0;
//开始循环
intervalId =setInterval(RollAround.marqueeright, RollAround.speedTime);
}
}

function getPage(type){
if(type=='left'){
var nextPageNo =currentPageNo + 1;
var div =  $('<div class="chapter" id="chapter_'+nextPageNo+'" style="margin-left:960px;"></div>')
div.append($('<a  href="#"><img src="css/img/unit_'+nextPageNo+'.jpg" align="图片"/></a>'));
return div;
}else{
var prevPageNo = currentPageNo -1;
var div =  $('<div class="chapter" id="chapter_'+prevPageNo+'" style="margin-left:-960px;"></div>')
div.append($('<a href="#"><img src="css/img/unit_'+prevPageNo+'.jpg" align="图片"/></a>'));
return div;
}
}

function getPxNumber(m){
var number = m.replace("px", "");
if(_isBlank(number)){
return 0;
}else{
return new Number(number);
}
}

function _isBlank(obj){
if(obj == null || obj == ""){
return true;
}
return false;
}
-->
</script>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics