<div class="codetitle"> <span><a style="CURSOR: pointer" data="41935" class="copybut" id="copybut41935" onclick="doCopy('code41935')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code41935"> <br><!--首页图片漂浮开始--> <br><script type="text/javascript" language="javascript"> <BR>function addEvent(obj, evtType, func, cap) { <BR>cap = cap || false; <BR>if (obj.addEventListener) { <BR>obj.addEventListener(evtType, func, cap); <BR>return true; <BR>} else if (obj.attachEvent) { <BR>if (cap) { <BR>obj.setCapture(); <BR>return true; <BR>} else { <BR>return obj.attachEvent("on" + evtType, func); <BR>} <BR>} else { <BR>return false; <BR>} <BR>} <BR>function getPageScroll() { <BR>var xScroll, yScroll; <BR>if (self.pageXOffset) { <BR>xScroll = self.pageXOffset; <BR>} else if (document.documentElement && document.documentElement.scrollLeft) { <BR>xScroll = document.documentElement.scrollLeft; <BR>} else if (document.body) { <BR>xScroll = document.body.scrollLeft; <BR>} <BR>if (self.pageYOffset) { <BR>yScroll = self.pageYOffset; <BR>} else if (document.documentElement && document.documentElement.scrollTop) { <BR>yScroll = document.documentElement.scrollTop; <BR>} else if (document.body) { <BR>yScroll = document.body.scrollTop; <BR>} <BR>arrayPageScroll = new Array(xScroll, yScroll); <BR>return arrayPageScroll; <BR>} <BR>function GetPageSize() { <BR>var xScroll, yScroll; <BR>if (window.innerHeight && window.scrollMaxY) { <BR>xScroll = document.body.scrollWidth; <BR>yScroll = window.innerHeight + window.scrollMaxY; <BR>} else if (document.body.scrollHeight > document.body.offsetHeight) { <BR>xScroll = document.body.scrollWidth; <BR>yScroll = document.body.scrollHeight; <BR>} else { <BR>xScroll = document.body.offsetWidth; <BR>yScroll = document.body.offsetHeight; <BR>} <BR>var windowWidth, windowHeight; <BR>if (self.innerHeight) { <BR>windowWidth = self.innerWidth; <BR>windowHeight = self.innerHeight; <BR>} else if (document.documentElement && document.documentElement.clientHeight) { <BR>windowWidth = document.documentElement.clientWidth; <BR>windowHeight = document.documentElement.clientHeight; <BR>} else if (document.body) { <BR>windowWidth = document.body.clientWidth; <BR>windowHeight = document.body.clientHeight; <BR>} <BR>if (yScroll < windowHeight) { <BR>pageHeight = windowHeight; <BR>} else { <BR>pageHeight = yScroll; <BR>} <BR>if (xScroll < windowWidth) { <BR>pageWidth = windowWidth; <BR>} else { <BR>pageWidth = xScroll; <BR>} <BR>arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight) <BR>return arrayPageSize; <BR>} <br><br>var AdMoveConfig = new Object(); <BR>AdMoveConfig.IsInitialized = false; <BR>AdMoveConfig.ScrollX = 0; <BR>AdMoveConfig.ScrollY = 0; <BR>AdMoveConfig.MoveWidth = 0; <BR>AdMoveConfig.MoveHeight = 0; <BR>AdMoveConfig.Resize = function () { <BR>var winsize = GetPageSize(); <BR>AdMoveConfig.MoveWidth = winsize[2]; <BR>AdMoveConfig.MoveHeight = winsize[3]; <BR>AdMoveConfig.Scroll(); <BR>} <BR>AdMoveConfig.Scroll = function () { <BR>var winscroll = getPageScroll(); <BR>AdMoveConfig.ScrollX = winscroll[0]; <BR>AdMoveConfig.ScrollY = winscroll[1]; <BR>} <BR>addEvent(window, "resize", AdMoveConfig.Resize); <BR>addEvent(window, "scroll", AdMoveConfig.Scroll); <BR>function AdMove(id) { <BR>if (!AdMoveConfig.IsInitialized) { <BR>AdMoveConfig.Resize(); <BR>AdMoveConfig.IsInitialized = true; <BR>} <BR>var obj = document.getElementById(id); <BR>obj.style.position = "absolute"; <BR>var W = AdMoveConfig.MoveWidth - obj.offsetWidth; <BR>var H = AdMoveConfig.MoveHeight - obj.offsetHeight; <BR>var x = W * Math.random(), y = H * Math.random(); <BR>var rad = (Math.random() + 1) * Math.PI / 6; <BR>var kx = Math.sin(rad), ky = Math.cos(rad); <BR>var dirx = (Math.random() < 0.5 ? 1 : -1), diry = (Math.random() < 0.5 ? 1 : -1); <BR>var step = 1; <BR>var interval; <BR>this.SetLocation = function (vx, vy) { x = vx; y = vy; } <BR>this.SetDirection = function (vx, vy) { dirx = vx; diry = vy; } <BR>obj.CustomMethod = function () { <BR>obj.style.left = (x + AdMoveConfig.ScrollX) + "px"; <BR>obj.style.top = (y + AdMoveConfig.ScrollY) + "px"; <BR>rad = (Math.random() + 1) * Math.PI / 6; <BR>W = AdMoveConfig.MoveWidth - obj.offsetWidth; <BR>H = AdMoveConfig.MoveHeight - obj.offsetHeight; <BR>x = x + step * kx * dirx; <BR>if (x < 0) { dirx = 1; x = 0; kx = Math.sin(rad); ky = Math.cos(rad); } <BR>if (x > W) { dirx = -1; x = W; kx = Math.sin(rad); ky = Math.cos(rad); } <BR>y = y + step * ky * diry; <BR>if (y < 0) { diry = 1; y = 0; kx = Math.sin(rad); ky = Math.cos(rad); } <BR>if (y > H) { diry = -1; y = H; kx = Math.sin(rad); ky = Math.cos(rad); } <BR>} <BR>this.Run = function () { <BR>var delay = 10; <BR>interval = setInterval(obj.CustomMethod, delay); <BR>obj.onmouseover = function () { clearInterval(interval); } <BR>obj.onmouseout = function () { interval = setInterval(obj.CustomMethod, delay); } <BR>} <BR>} <BR></script> <br><!--漂浮开始--> <br><div id="ad2" style="Z-INDEX: 5;position:relative"> <br><br><a href="PoliceHTk.aspx" target="_blank"><img src="images/fudong/fudong.jpg" style="max-width:90%" style="max-width:90%" border="0" alt="首页图片漂浮效果示例代码_javascript技巧" > </a><br> <a href="#" onclick="document.getElementById('ad2').style.display='none'"> <img border="0" src="images/fudong/close1.gif" alt="首页图片漂浮效果示例代码_javascript技巧" ></a> <br><!--漂浮结束--> <br> </div> <br><script type="text/javascript" language="javascript"> <br><br>var ad2 = new AdMove("ad2"); <BR>ad2.Run(); <BR>//多组漂浮 <br><br></script> <br><!-- 首页图片漂浮结束 --> <br> </div>