网站制作技巧之鼠标控制图片滚动
很多网站可以看到精美的鼠标控制图片滚动的效果?比如上下滚动、左右滚动啊,你想知道是怎么实现的吗?下面我们网站制作工作室就放出这一鼠标控制图片滚动的小技巧:
鼠标控制图片上下滚动:
<div align="center"><script language="JavaScript">
function scroll(n)
{temp=n;
News.scrollTop=News.scrollTop+temp;
if (temp==0) return;
setTimeout("scroll(temp)",20);
}
</script><table border="0" width="100%" cellpadding="0" style="border-collapse: collapse" id="table11">
<tr><td height="10"></td></tr>
<tr>
<td>
<img OnMouseDown="scroll(-3)" OnMouseOver="scroll(-3)" style="CURSOR: hand" OnMouseOut="scroll(0)" border="0" src="Selbt_Up.gif" width="100" height="16" title="按下鼠标速度会更快"></td>
</tr>
<tr>
<td height="25" style="padding-top:5px; padding-bottom:5px;"><div id="News" style="border:0px dashed; OVERFLOW: hidden; WIDTH: 100px; HEIGHT: 300px; ">
<div align="center">
<table border="0" width="100%" cellpadding="0" style="border-collapse: collapse" id="table31">
<tr>
<td>
<TABLE id=ctl02_ctl00_DL_template_ctl05_ctl00_DL_List_1
style="WIDTH: 100%; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0
align=center border=0>
<TBODY>
<TR>
<TD height=110>
<a href="chanpinShow.asp?ID=707" target="pro"><img class=template_pic_image src="../uploadfiles/2010420162155147.jpg" alt="鼠标控制图片滚动" width="98" height="100" border="1" style="border-color:#cccccc" /></a></TD>
<TD>
</tr><tr>
<TD height=110>
<a href="chanpinShow.asp?ID=706" target="pro"><img class=template_pic_image src="../uploadfiles/2010420161555934.jpg" alt="鼠标控制图片滚动" width="98" height="100" border="1" style="border-color:#cccccc" /></a></TD>
<TD>
</tr><tr>
<TD height=110>
<a href="chanpinShow.asp?ID=705" target="pro"><img class=template_pic_image src="../uploadfiles/2010420161519329.jpg" alt="鼠标控制图片滚动" width="98" height="100" border="1" style="border-color:#cccccc" /></a></TD>
<TD>
</tr><tr>
<TD height=110>
<a href="chanpinShow.asp?ID=703" target="pro"><img class=template_pic_image src="../uploadfiles/201042016738903.jpg" alt="鼠标控制图片滚动" width="98" height="100" border="1" style="border-color:#cccccc" /></a></TD>
<TD>
</tr><tr>
<TD height=110>
<a href="chanpinShow.asp?ID=704" target="pro"><img class=template_pic_image src="../uploadfiles/2010420161351590.jpg" alt="鼠标控制图片滚动" width="98" height="100" border="1" style="border-color:#cccccc" /></a></TD>
<TD>
</tr><tr></TR></TBODY></TABLE>
</td>
</tr>
</table>
</div>
</div></td>
</tr>
<tr>
<td>
<img OnMouseDown="scroll(3)" OnMouseOver="scroll(3)" style="CURSOR: hand" OnMouseOut="scroll(0)" border="0" src="Selbt_Down.gif" width="100" height="16" title="按下鼠标速度会更快"></td>
</tr>
<tr>
</tr>
</table>
</div>
网站制作技巧之二
鼠标控制图片左右滚动:
<div class="rollBox">
<div class="LeftBotton" Onmousedown="ISL_GoUp()" Onmouseup="ISL_StopUp()" Onmouseout="ISL_StopUp()"></div>
<div class="Cont" id="ISL_Cont">
<div class="ScrCont">
<div id="List1">
<!-- 图片列表 begin -->
<div class="pic">
<img src="" width="109" height="87" alt="" />
</div>
<div class="pic">
<img src="" width="109" height="87" alt="" />
</div>
<div class="pic">
<img src="" width="109" height="87" alt="" />
</div>
<div class="pic">
<img src="" width="109" height="87" alt="" />
</div>
<div class="pic">
<img src="" width="109" height="87" alt="" />
</div>
<div class="pic">
<img src="" width="109" height="87" alt="" />
</div>
<div class="pic">
<img src="" width="109" height="87" alt="" />
</div>
<!-- 图片列表 end -->
</div>
<div id="List2"></div>
</div>
</div>
<div class="RightBotton" Onmousedown="ISL_GoDown()" Onmouseup="ISL_StopDown()" Onmouseout="ISL_StopDown()"></div>
</div>
</div>
<style type="text/css">
<!--
.rollBox{width:704px;overflow:hidden;padding:12px 0 5px 6px;}
.rollBox .LeftBotton{height:52px;width:19px;background:url(images/kztpgd.gif) no-repeat 11px 0;overflow:hidden;float:left;display:inline;margin:25px 0 0 0;cursor:pointer;}
.rollBox .RightBotton{height:52px;width:16px;background:url(images/kztpgd.gif) no-repeat -8px 0;overflow:hidden;float:left;display:inline;margin:25px 0 0 0;cursor:pointer;}
.rollBox .Cont{width:663px;overflow:hidden;float:left;}
.rollBox .ScrCont{width:10000000px;}
.rollBox .Cont .pic{width:132px;float:left;text-align:center;}
.rollBox .Cont .pic img{padding:4px;background:#fff;border:1px solid #ccc;display:block;margin:0 auto;}
.rollBox .Cont .pic p{line-height:26px;color:#505050;}
.rollBox .Cont a:link,.rollBox .Cont a:visited{color:#626466;text-decoration:none;}
.rollBox .Cont a:hover{color:#f00;text-decoration:underline;}
.rollBox #List1,.rollBox #List2{float:left;}
-->
</style>
<script language="Javascript" type="text/Javascript">
<!--//--><![CDATA[//><!--
//图片滚动列表 mengjia 070816
var Speed = 10; //速度(毫秒)
var Space = 5; //每次移动(px)
var PageWidth = 132; //翻页宽度
var fill = 0; //整体移位
var MoveLock = false;
var MoveTimeObj;
var Comp = 0;
var AutoPlayObj = null;
GetObj("List2").innerHTML = GetObj("List1").innerHTML;
GetObj('ISL_Cont').scrollLeft = fill;
GetObj("ISL_Cont").Onmouseover = function(){clearInterval(AutoPlayObj);}
GetObj("ISL_Cont").Onmouseout = function(){AutoPlay();}
AutoPlay();
function GetObj(objName){if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}}
function AutoPlay(){ //自动滚动
clearInterval(AutoPlayObj);
AutoPlayObj = setInterval('ISL_GoDown();ISL_StopDown();',10000000); //间隔时间
}
function ISL_GoUp(){ //上翻开始
if(MoveLock) return;
clearInterval(AutoPlayObj);
MoveLock = true;
MoveTimeObj = setInterval('ISL_ScrUp();',Speed);
}
function ISL_StopUp(){ //上翻停止
clearInterval(MoveTimeObj);
if(GetObj('ISL_Cont').scrollLeft % PageWidth - fill != 0){
Comp = fill - (GetObj('ISL_Cont').scrollLeft % PageWidth);
CompScr();
}else{
MoveLock = false;
}
AutoPlay();
}
function ISL_ScrUp(){ //上翻动作
if(GetObj('ISL_Cont').scrollLeft <= 0){GetObj('ISL_Cont').scrollLeft = GetObj('ISL_Cont').scrollLeft + GetObj('List1').offsetWidth}
GetObj('ISL_Cont').scrollLeft -= Space ;
}
function ISL_GoDown(){ //下翻
clearInterval(MoveTimeObj);
if(MoveLock) return;
clearInterval(AutoPlayObj);
MoveLock = true;
ISL_ScrDown();
MoveTimeObj = setInterval('ISL_ScrDown()',Speed);
}
function ISL_StopDown(){ //下翻停止
clearInterval(MoveTimeObj);
if(GetObj('ISL_Cont').scrollLeft % PageWidth - fill != 0 ){
Comp = PageWidth - GetObj('ISL_Cont').scrollLeft % PageWidth + fill;
CompScr();
}else{
MoveLock = false;
}
AutoPlay();
}
function ISL_ScrDown(){ //下翻动作
if(GetObj('ISL_Cont').scrollLeft >= GetObj('List1').scrollWidth){GetObj('ISL_Cont').scrollLeft = GetObj('ISL_Cont').scrollLeft - GetObj('List1').scrollWidth;}
GetObj('ISL_Cont').scrollLeft += Space ;
}
function CompScr(){
var num;
if(Comp == 0){MoveLock = false;return;}
if(Comp < 0){ //上翻
if(Comp < -Space){
Comp += Space;
num = Space;
}else{
num = -Comp;
Comp = 0;
}
GetObj('ISL_Cont').scrollLeft -= num;
setTimeout('CompScr()',Speed);
}else{ //下翻
if(Comp > Space){
Comp -= Space;
num = Space;
}else{
num = Comp;
Comp = 0;
}
GetObj('ISL_Cont').scrollLeft += num;
setTimeout('CompScr()',Speed);
}
}
//--><!]]>
</script>
注:超粗黑色的字母J和O改成正常字母j和o;如果你也像我一样懒那就点这里下载鼠标控制图片左右滚动和上下滚动的代码吧。鼠标控制图片上下左右滚动.rar