標籤:
點擊按鈕開始整體右移,移動至藍色地區全部顯示出來停止。
<!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" /><title>無標題文檔</title><style type="text/css">*{ margin:0px; padding:0px;}#wai{ width:0px; height:600px;}</style></head><body><input id="anniu1" type="image" value="開始" src="12Nc43961Z-15Y04.png" style=" width:40px; height:40px;position:absolute;left:190px; top:300px; margin-left:0px; display:block" onclick="right()" />--按鈕1<input id="anniu2" type="image" value="開始" src="Kuaiwan.ico" style=" width:40px; height:40px;position:absolute;right:190px; top:300px; margin-right:0px; display:none" onclick="left()" />--按鈕2<div style="width:100%; height:600px; overflow:hidden">--限制圖片大小,超出部分隱藏 <div style="width:3200px; height:600px;"> <div id="d1" style="width:1349px; height:600px; background-color:#309; float:left; margin-left:-1149px;">--藍色圖片 </div> <div id="d2" style="width:1349px; height:600px; background-color:#F03; float:left;">--紅色圖片 </div> </div></div></body><script type="text/javascript">function right()//向右滑動{ if(parseInt(d1.style.marginLeft)<=-200)//藍色圖片左邊距小於-200,始終給紅色留下200px顯示 { var a=parseInt(d1.style.marginLeft)+5; d1.style.marginLeft=a+"px"; var aa=parseInt(anniu1.style.marginLeft)+5; anniu1.style.marginLeft=aa+"px"; window.setTimeout("right()",3);//每隔3毫秒藍色圖片和按鈕1的邊距各加5像素 } else//if(parseInt(anniu1.style.marginLeft)>=949) { anniu1.style.display="none";//圖片和按鈕1到頭隱藏,顯示按鈕2,按鈕1邊距歸零 anniu2.style.marginRight="0px"; anniu2.style.display="block"; }}function left()//向左滑動{ if(parseInt(d1.style.marginLeft)>-1149)//圖片和按鈕2向左每隔3毫秒增加5px滑動,到左邊距為-1149px時停止滑動 { var b=parseInt(d1.style.marginLeft)-5; d1.style.marginLeft=b+"px"; var bb=parseInt(anniu2.style.marginRight)+5; anniu2.style.marginRight=bb+"px"; window.setTimeout("left()",3); } else//if(parseInt(d1.style.marginLeft)<=-1149)滑動到頭時,按鈕1顯示,按鈕2隱藏,按鈕2左邊距歸零 { //alert("2"); anniu2.style.display="none"; anniu1.style.marginLeft="0px"; anniu1.style.display="block"; }}</script></html>
JAVASCRIPT——圖片滑動效果