日期:2014-05-16 浏览次数:20362 次
<!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> <style type="text/css"> #focus_box{ width:530px; height:180px; position:relative; margin:0 auto;overflow:hidden } #focus_box ul{ list-style:none; padding:0; margin:0;} #focus_btn{ position:absolute; right:5px; bottom:5px; z-index:2;} #focus_pic{ position:absolute; top:-180px;} #focus_pic li{ height:180px; width:530px; margin:0; padding:0;} #focus_btn li{ float:left; font-size:12px; width:25px; height:25px; line-height:25px; font-weight:bold; text-align:center; background:#fff; color:#000; margin-right:2px; cursor:pointer;} #focus_btn li.on{ background:#f60; color:#fff;} </style> </head> <body> <div id="focus_box" > <ul id="focus_pic" style="left:0;top:0;"> <li><a target="_blank" href="#"><img src="http://img.fqmall.cn/WebResources/boc/Xdv/shopping/images/20111201/530_180.jpg" width="530" height="180"></a></li> <li><a target="_blank" href="#"><img src="http://img.fqmall.cn/WebResources/boc/Xdv/shopping/images/20111202/530_180.jpg" width="530" height="180"></a></li> <li><a target="_blank" href="#"><img src="http://img.fqmall.cn/WebResources/boc/Xdv/shopping/images/20111205/530_180.jpg" width="530" height="180"></a></li> </ul> <ul id="focus_btn"> <li class="on">1</li> <li class="">2</li> <li class="">3</li> </ul> </div> <script type="text/javascript"> var picHeight = 180;//幻灯片的高度 var picWidth = 530;//幻灯片的宽度 var autoTime = 1000;//自动播放间隔时间 var focusPics = document.getElementById("focus_pic");//获得幻灯片的框架ID var picNo = focusPics.getElementsByTagName("li").length;//幻灯片的数量 function autoPlay(){ var topScroll = -picHeight; var int = function (){ var move = "moveElement("+ 0 + "," + topScroll + ")"; IntTimer = setInterval(move,10); //clearTimeout(timer); } timer = setTimeout(int,autoTime);//只播放一次就不播放了。。。。。。。。 } function moveElement(posX,posY){//移动到目标距离函数 var stepx,stepy; if(!focusPics.style.left) focusPics.style.left = "0px"; if(!focusPics.style.top) focusPics.style.top = "0px"; var left = focusPics.style.left; var top = focusPics.style.top; left = parseInt(left,10); top = parseInt(top,10); if(left == posX&&top==posY){ return false; }; if(left>posX){ stepx = Math.ceil((left-posX)/10); left = left - stepx; }else if(left<posX){ stepx = Math.ceil((posX-left)/10); left = left + stepx; } if(top>posY){ stepy = Math.ceil((top-posY)/10); top = top - stepy; }else if(top<posY){ stepy = Math.ceil((posY - top)/10); top = top + stepy; } focusPics.style.left = left + "px"; focusPics.style.top = top + "px"; } autoPlay(); </script> </body> </html>