漂浮廣告代碼不兼容瀏覽器,不動的解決辦法
在給元素位置賦值的時候把單位(px)給加上就行了,
原來的代碼:
obj.style.left = x + document.documentElement.scrollLeft;
修改后的代碼:
obj.style.left = x + document.documentElement.scrollLeft+"px";
================================================================================
<!--漂浮開始--><DIV id=img1 style="Z-INDEX: 100; LEFT: 2px; WIDTH: 59px; POSITION: absolute; TOP: 310px; HEIGHT: 61px;
visibility: visible;"><a href="news.asp?classID=11"><img src="/images/ad.jpg" width="200" height="160" border="0"></a></DIV><!--漂浮結(jié)束-->
<!--漂浮開始-->
<SCRIPT>
var xPos = 300;
var yPos = 200;
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
img1.style.top = yPos;
function changePos()
{
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img1.offsetHeight;
Woffset = img1.offsetWidth;
img1.style.left = xPos + document.body.scrollLeft+"px";
img1.style.top = yPos + document.body.scrollTop+"px";
if (yon)
{yPos = yPos + step;}
else
{yPos = yPos - step;}
if (yPos < 0)
{yon = 1;yPos = 0;}
if (yPos >= (height - Hoffset))
{yon = 0;yPos = (height - Hoffset);}
if (xon)
{xPos = xPos + step;}
else
{xPos = xPos - step;}
if (xPos < 0)
{xon = 1;xPos = 0;}
if (xPos >= (width - Woffset))
{xon = 0;xPos = (width - Woffset); }
}
function start()
{
img1.visibility = "visible";
interval = setInterval('changePos()', delay);
}
function pause_resume()
{
if(pause)
{
clearInterval(interval);
pause = false;}
else
{
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
</SCRIPT>
<!--漂浮結(jié)束-->
標簽: 濟南網(wǎng)站建設(shè) 網(wǎng)站建設(shè) 濟南網(wǎng)站制作 網(wǎng)址: www.haoli824.com
- 打印本文
- 關(guān)閉本頁
- 建站服務(wù)熱線:0531-68808868 售后服務(wù)專線:0531-88961515