左右拖曳翻页效果JS代码

左右拖曳翻页效果js源代码
<html>
<head>
<title>blog</title>
<meta http-equiv=content-type content="text/html; charset=gb2312">
<style>
body{
 border:0px;
 margin:0px;
 overflow:hidden;
 background-color:transparent;
 font-family:宋体;
}
.page{
 position:absolute;
 700px;
 border:1px solid #999;
 background-color:#000;
 left:425px;
 margin-left:-350px;
 cursor:default;
 z-index:0;
}
ul{
 height:320px;
 list-style:none;
 margin:40px 50px 0px;
 padding:0px;
}
li{
 100%;
 height:30px;
 line-height:30px;
 font-size:14px;
 text-align:left;
 border-bottom:1px dashed #999;
}
a{
 text-decoration:none;
 color:#999;
}
a:hover{
 font-weight:bold;
}
li span{
 float:right;
 color:#999;
}
.tip{
 display:block;
 100%;
 font-size:12px;
 color:#999;
 text-align:center;
 margin:10px 0px 20px;
}
</style>
</head>
<body onselectstart="return false;">
<script>
function id(obj){
 return document.getElementById(obj);
}
var page;
var lm,mx;
var md=false;
var sh=0;
var en=false;
window.onload=function(){
 page=document.getElementsByTagName("div");
 if(page.length>0){
  page[0].style.zIndex=2;
 }
 for(i=0;i<page.length;i++){
  page[i].className="page";
  page[i].innerHTML+="<span class="tip">第 "+(i+1)+"/"+page.length+" 页 提示:左右拖拽翻页</span>";
  page[i].id="page"+i;
  page[i].i=i;
  page[i].onmousedown=function(e){
   if(!en){
    if(!e){e=e||window.event;}
    lm=this.offsetLeft;
    mx=(e.pageX)?e.pageX:e.x;
    this.style.cursor="w-resize";
    md=true;
    if(document.all){
     this.setCapture();
    }else{
     window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
    }
   }
  }
  page[i].onmousemove=function(e){
   if(md){
    en=true;
    if(!e){e=e||window.event;}
    var ex=(e.pageX)?e.pageX:e.x;
    this.style.left=ex-(mx-lm)+350;
   
   
   
   
    if(this.offsetLeft<75){
     var cu=(this.i==0)?page.length-1:this.i-1;
     page[sh].style.zIndex=0;
     page[cu].style.zIndex=1;
     this.style.zIndex=2;
     sh=cu;
    }
    if(this.offsetLeft>75){
     var cu=(this.i==page.length-1)?0:this.i+1;
     page[sh].style.zIndex=0;
     page[cu].style.zIndex=1;
     this.style.zIndex=2;
     sh=cu;
    }
   
   
   
   
   
   
   
   }
  }
  page[i].onmouseup=function(){
   this.style.cursor="default";
   md=false;
   if(document.all){
    this.releaseCapture();
   }else{
    window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
   }
   flyout(this);
  }
 }
}
function flyout(obj){
 if(obj.offsetLeft<75){
  if(  (obj.offsetLeft + 350 - 20) > -275 ){
   obj.style.left=obj.offsetLeft + 350 - 20;
   window.setTimeout("flyout(id('"+obj.id+"'));",0);
  }else{
   obj.style.left=-275;
   obj.style.zIndex=0;
   flyin(id(obj.id));
  }
 }
 if(obj.offsetLeft>75){
  if(  (obj.offsetLeft + 350 + 20) < 1125 ){
   obj.style.left=obj.offsetLeft + 350 + 20;
   window.setTimeout("flyout(id('"+obj.id+"'));",0);
  }else{
   obj.style.left=1125;
   obj.style.zIndex=0;
   flyin(id(obj.id));
  }
 }
}
function flyin(obj){
 if(obj.offsetLeft<75){
  if(  (obj.offsetLeft + 350 + 20) < 425  ){
   obj.style.left=obj.offsetLeft + 350 + 20;
   window.setTimeout("flyin(id('"+obj.id+"'));",0);
  }else{
   obj.style.left=425;
   en=false;
  }
 }
 if(obj.offsetLeft>75){
  if(  (obj.offsetLeft + 350 - 20) > 425  ){
   obj.style.left=obj.offsetLeft + 350 - 20;
   window.setTimeout("flyin(id('"+obj.id+"'));",0);
  }else{
   obj.style.left=425;
   en=false;
  }
 }
}
</script>
<div>
 <ul>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>fuck</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>啊</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>oklet'sgo</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>thisyear</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>abcdefg</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>gfedcba</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>abcdefg</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>gfedcba</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>abcdefg</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>ohmygod</a></li>
 </ul>
</div>
<div>
 <ul>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>abcdefg</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>abcdefg</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>ohmygod</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>gfedcba</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>vadfasdf</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>asdfvcx</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>abcdsaf</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>eerrrrrr</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>aaaaaaaaaa</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>bbbbbbbbb</a></li>
 </ul>
</div>
<div>
 <ul>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>cccccccccc</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>ddddd</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>eeee</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>ffff</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>gggggggggg</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>hhhhhhh</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>wwwwwwwww</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>qqqqqqqqq</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>eee</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>rrrrrr</a></li>
 </ul>
</div>
<div>
 <ul>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>ssssss</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>aaaaa</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>vvvvvvv</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>bbbbbbx</a></li>
  <li><span>2011-12-10 23:42</span><a href=http://www.hackpro.cn>xxxxxxx</a></li>
 </ul>
</div>
</body>
</html>
本文来自胡摘网[http://z.hackpro.cn],转载请标明出处:http://www.hackpro.cn/art/3489.html
原文地址:https://www.cnblogs.com/superfans/p/2103589.html