網(wǎng)站制作技巧之鼠標(biāo)控制圖片滾動(dòng)
很多網(wǎng)站可以看到精美的鼠標(biāo)控制圖片滾動(dòng)的效果?比如上下滾動(dòng)、左右滾動(dòng)啊,你想知道是怎么實(shí)現(xiàn)的嗎?下面我們網(wǎng)站制作工作室就放出這一鼠標(biāo)控制圖片滾動(dòng)的小技巧:
鼠標(biāo)控制圖片上下滾動(dòng):
<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="按下鼠標(biāo)速度會(huì)更快"></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="鼠標(biāo)控制圖片滾動(dòng)" 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="鼠標(biāo)控制圖片滾動(dòng)" 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="鼠標(biāo)控制圖片滾動(dòng)" 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="鼠標(biāo)控制圖片滾動(dòng)" 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="鼠標(biāo)控制圖片滾動(dòng)" 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="按下鼠標(biāo)速度會(huì)更快"></td>
</tr>
<tr>
</tr>
</table>
</div>
網(wǎng)站制作技巧之二
鼠標(biāo)控制圖片左右滾動(dòng):
<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[//><!--
//圖片滾動(dòng)列表 mengjia 070816
var Speed = 10; //速度(毫秒)
var Space = 5; //每次移動(dòng)(px)
var PageWidth = 132; //翻頁(yè)寬度
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(){ //自動(dòng)滾動(dòng)
clearInterval(AutoPlayObj);
AutoPlayObj = setInterval('ISL_GoDown();ISL_StopDown();',10000000); //間隔時(shí)間
}
function ISL_GoUp(){ //上翻開(kāi)始
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(){ //上翻動(dòng)作
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(){ //下翻動(dòng)作
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;如果你也像我一樣懶那就點(diǎn)這里下載鼠標(biāo)控制圖片左右滾動(dòng)和上下滾動(dòng)的代碼吧。鼠標(biāo)控制圖片上下左右滾動(dòng).rar