技术文章
当前位置:首页 > 技术文章

JS控制图片左右滚动代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="clickfloat.aspx.cs" Inherits="clickfloat" %>
<!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=gb2312" />
<title>图片</title>
<script type="text/javascript">
<!--
var Speed_1 = 10; //速度(毫秒)
var Space_1 = 20; //每次移动(px)
var PageWidth_1 = 116 * 7; //翻页宽度
var interval_1 = 20000; //翻页间隔
var fill_1 = 0; //整体移位
var MoveLock_1 = false;
var MoveTimeObj_1;
var MoveWay_1="right";
var Comp_1 = 0;
var AutoPlayObj_1=null;
function GetObj(objName){if(document.getElementById){return eval(''document.getElementById("''+objName+''")'')}else{return eval(''document.all.''+objName)}}
function AutoPlay_1(){clearInterval(AutoPlayObj_1);AutoPlayObj_1=setInterval(''JflC_GoDown_1();JflC_StopDown_1();'',interval_1)}
function JflC_GoUp_1(){if(MoveLock_1)return;clearInterval(AutoPlayObj_1);MoveLock_1=true;MoveWay_1="left";MoveTimeObj_1=setInterval(''JflC_ScrUp_1();'',Speed_1);}
function JflC_StopUp_1(){if(MoveWay_1 == "right"){return};clearInterval(MoveTimeObj_1);if((GetObj(''JflC_1'').scrollLeft-fill_1)%PageWidth_1!=0){Comp_1=fill_1-(GetObj(''JflC_1'').scrollLeft%PageWidth_1);JflComp_1()}else{MoveLock_1=false}
AutoPlay_1()}
function JflC_ScrUp_1(){if(GetObj(''JflC_1'').scrollLeft<=0){GetObj(''JflC_1'').scrollLeft=GetObj(''JflC_1'').scrollLeft+GetObj(''Jlist1_1'').offsetWidth}
GetObj(''JflC_1'').scrollLeft-=Space_1}
function JflC_GoDown_1(){clearInterval(MoveTimeObj_1);if(MoveLock_1)return;clearInterval(AutoPlayObj_1);MoveLock_1=true;MoveWay_1="right";JflC_ScrDown_1();MoveTimeObj_1=setInterval(''JflC_ScrDown_1()'',Speed_1)}
function JflC_StopDown_1(){if(MoveWay_1 == "left"){return};clearInterval(MoveTimeObj_1);if(GetObj(''JflC_1'').scrollLeft%PageWidth_1-(fill_1>=0?fill_1:fill_1+1)!=0){Comp_1=PageWidth_1-GetObj(''JflC_1'').scrollLeft%PageWidth_1+fill_1;JflComp_1()}else{MoveLock_1=false}
AutoPlay_1()}
function JflC_ScrDown_1(){if(GetObj(''JflC_1'').scrollLeft>=GetObj(''Jlist1_1'').scrollWidth){GetObj(''JflC_1'').scrollLeft=GetObj(''JflC_1'').scrollLeft-GetObj(''Jlist1_1'').scrollWidth}
GetObj(''JflC_1'').scrollLeft+=Space_1}
function JflComp_1(){if(Comp_1==0){MoveLock_1=false;return}
var num,TempSpeed=Speed_1,TempSpace=Space_1;if(Math.abs(Comp_1)<PageWidth_1/2){TempSpace=Math.round(Math.abs(Comp_1/Space_1));if(TempSpace<1){TempSpace=1}}
if(Comp_1<0){if(Comp_1<-TempSpace){Comp_1+=TempSpace;num=TempSpace}else{num=-Comp_1;Comp_1=0}
GetObj(''JflC_1'').scrollLeft-=num;setTimeout(''JflComp_1()'',TempSpeed)}else{if(Comp_1>TempSpace){Comp_1-=TempSpace;num=TempSpace}else{num=Comp_1;Comp_1=0}
GetObj(''JflC_1'').scrollLeft+=num;setTimeout(''JflComp_1()'',TempSpeed)}}
function ImageRun(){
GetObj("Jlist2_1").innerHTML=GetObj("Jlist1_1").innerHTML;
GetObj(''JflC_1'').scrollLeft=fill_1>=0?fill_1:GetObj(''Jlist1_1'').scrollWidth-Math.abs(fill_1);
GetObj("JflC_1").onmouseover=function(){clearInterval(AutoPlayObj_1)}
GetObj("JflC_1").onmouseout=function(){AutoPlay_1()}
AutoPlay_1();
}
//-->
</script>
<style type="text/css">
<!--
BODY {
border: 0px;FONT-SIZE: 12px;
}
.Jblk_18 {
width: 890px; z-index:1
}
.Jblk_18 .pcont {
float: left; overflow: hidden; width: 850px
}
.Jblk_18 .ScrCont {
width: 15000px; z-index:1
}
.Jblk_18 #Jlist1_1 {
float: left
}
.Jblk_18 #Jlist2_1 {
float: left
}
.Jblk_18 .LeftBotton {
background: url(edupload/picr_1.gif) no-repeat; float: left; margin: 10px 1px; width: 15px; height: 72px
}
.Jblk_18 .RightBotton {
background: url(edupload/picr_1.gif) no-repeat; float: left; margin: 10px 1px; width: 15px; height: 72px
}
.Jblk_18 .LeftBotton {
background-position: 0px 0px; margin-LEFT: 5px
}
.Jblk_18 .RightBotton {
background-position: 0px -100px; margin-LEFT: -1px
}
.Jblk_18 .LeftBotton:hover {
background-position: -20px 0px
}
.Jblk_18 .RightBotton:hover {
background-position: -20px -100px
}
.Jblk_18 .pl img {
DISPLAY: block; margin: 6px auto 1px; CURSOR: pointer; border-top-STYLE: none; border-RIGHT-STYLE: none; border-LEFT-STYLE: none; border-BOTTOM-STYLE: none
}
.Jblk_18 .pl {
border:#f3f3f3 1px solid; float: left; width: 114px; LINE-height: 24px; TEXT-ALIGN: center; TEXT-DECORATION: underline
}
.Jblk_18 A.pl:hover {
border:#ff9900 1px solid; COLOR: #ff9900;
}
-->
</style>
</head>
<body>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<div class="Jblk_18">
<a onmouseup="JflC_StopUp_1()" class="LeftBotton" onmousedown="JflC_GoUp_1()" onmouseout="JflC_StopUp_1()"></a>
<div class="pcont" id="JflC_1">
<div class="ScrCont">
<div id="Jlist1_1">
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808012828.jpg" />1</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808013002.jpg" />2</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808012828.jpg" />3</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808021217.jpg" />4</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808023509.jpg" />5</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808023720.jpg" />6</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808024131.jpg" />7</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808030501.jpg" />8</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808035505.jpg" />9</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808040646.jpg" />10</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808040243.jpg" />11</a>
<a class="pl" href="#"><img height="70" width="95" src="edupload/20100808122338.jpg" />12</a>
</div>
<div id="Jlist2_1"></div>
</div>
</div>
<a onmouseup="JflC_StopDown_1()" class="RightBotton" onmousedown="JflC_GoDown_1()" onmouseout="JflC_StopDown_1()"></a>
</div>
<script type="text/javascript">
<!--
ImageRun();
//-->
</script>
</td>
</tr>
</table>
</body>
</html>