日期:2014-05-16 浏览次数:20604 次
<!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> <style type="text/css" > #div1{ position:relative;height:800px; border:1px solid red;} #div1 img{ position:absolute;} </style> </head> <body > <div id="div1" > <img src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" /> <img src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" /> <img src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" /> <img src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" /> <img src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" /> <img src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" /> </div> <script type="text/javascript" > var centerx = 400;//圆心X var centery = 300; //圆心Y var r = 300; //半径 var oimages = document.getElementById("div1").getElementsByTagName("IMG"); //图片集合 var cnt = oimages.length;//图片数 var da = 360/cnt;//图片间隔角度 var a0 = 0; //已旋转角度 var timer; for (var i = 0; i < cnt; i++) { oimages[i].onmouseover = stop; oimages[i].onmouseout = start; } function posimgs() { for (var i = 0; i < cnt; i++) { oimages[i].style.left = centerx + r*Math.cos((da * i + a0) / 180 * Math.PI) + "px"; oimages[i].style.top = centery +r* Math.sin((da * i + a0) / 180 * Math.PI) + "px"; } } // posimgs(); function start() { timer = window.setInterval("posimgs();a0++;", 100); } function stop() { window.clearInterval(timer); } start(); </script> </body> </html>
------解决方案--------------------
刚才看到楼主私信我能不能让几个围绕一个转,也很简单,把以上代码稍改动一点点就行了。
我假设是其它的图都围绕第一个转,只有我标红的地方改一下
//以上不变 var da = 360/([color=#FF0000]cnt-1[/color]);//图片间隔角度 var a0 = 0; //已旋转角度 var timer; [color=#FF0000] oimages[0].style.left = centerx + "px"; oimages[0].style.top = centery + "px";[/color] for (var i = [color=#FF0000]1[/color]; i < cnt; i++) { oimages[i].onmouseover = stop; oimages[i].onmouseout = start; } function posimgs() { for (var i = [color=#FF0000]1[/color]; i < cnt; i++) { oimages[i].style.left = centerx + r*Math.cos((da * i + a0) / 180 * Math.PI) + "px"; oimages[i].style.top = centery +r* Math.sin((da * i + a0) / 180 * Math.PI) + "px"; } } // posimgs(); //其它不变
------解决方案--------------------
显示有问题没有标红,我重发一下
var da = 360/(cnt-1);
以下两句是新增的,
oimages[0].style.left = centerx + "px";
oimages[0].style.top = centery + "px";
以下就是将for(var i=0
将i=0改成i=1