XHTML中有关浮动图标实现的代码

来源:互联网 发布:2016淘宝下载安装 编辑:程序博客网 时间:2024/06/03 21:59

不必去除页面最上头的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
代码一样可以实现浮动广告的效果。


<script type="text/javascript">
   //<![CDATA[
   var adLeftSrc = ""
   var adLeftFlash = ""
   var adLeftHref = ""
   var adLeftWidth = 80
   var adLeftHeight = 80
   var adRightSrc = "XXX.GIF"
   var adRightFlash = "flash"
   var adRightHref = ""
   var adRightWidth = 80
   var adRightHeight = 80
   var marginTop = 20
   var marginLeft = 20
   var navUserAgent = navigator.userAgent
   function load(){
    judge();
    move();
   }
   function move() {
    judge();
    setTimeout("move();",80)
   }
   function judge(){
    if (navUserAgent.indexOf("Firefox") >= 0 || navUserAgent.indexOf("Opera") >= 0) {
     if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - adLeftHeight - marginTop + 'px';}
     if (adRightSrc != "") {
      document.getElementById("adRightFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - adRightHeight - marginTop + 'px';
      document.getElementById("adRightFloat").style.left = ((document.body.clientWidth > document.documentElement.clientWidth)?document.body.clientWidth:document.documentElement.clientWidth) - adRightWidth - marginLeft + 'px';
     }
    }
    else{
     if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.documentElement.clientHeight == 0)?document.body.clientHeight:document.documentElement.clientHeight) - adLeftHeight - marginTop + 'px';}
     if (adRightSrc != "") {
      document.getElementById("adRightFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.documentElement.clientHeight == 0)?document.body.clientHeight:document.documentElement.clientHeight) - adRightHeight - marginTop + 'px';
      document.getElementById("adRightFloat").style.left = ((document.documentElement.clientWidth == 0)?document.body.clientWidth:document.documentElement.clientWidth) - adRightWidth - marginLeft + 'px';
     }
    }
    if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.left = marginLeft + 'px';}
   }
   if (adLeftSrc != "") {
    if (adLeftFlash == "flash") {
     document.write("<div id=/"adLeftFloat/" style=/"position: absolute;width:" + adLeftWidth + ";/"><a href=/"" + adLeftHref +"/"><embed src=/"" + adLeftSrc + "/" quality=/"high/"  width=/"" + adLeftWidth + "/" height=/"" + adLeftHeight + "/" type=/"application/x-shockwave-flash/"></embed></a></div>");
    }
    else{
     document.write("<div id=/"adLeftFloat/" style=/"position: absolute;width:" + adLeftWidth + ";/"><a href=/"" + adLeftHref +"/" target=_blank><img src=/"" + adLeftSrc + "/"  width=/"" + adLeftWidth + "/" height=/"" + adLeftHeight + "/"  border=/"0/" /></a></div>");
    }
   }
   if (adRightSrc != "") {
    if (adRightFlash == "flash") {
     document.write("<div id=/"adRightFloat/" style=/"position: absolute;width:" + adRightWidth + ";/"><a href=/"" + adRightHref +"/"><embed src=/"" + adRightSrc + "/" quality=/"high/"  width=/"" + adLeftWidth + "/" height=/"" + adRightHeight + "/" type=/"application/x-shockwave-flash/"></a></embed></div>");
    }
    else{
     document.write("<div id=/"adRightFloat/" style=/"position: absolute;width:" + adRightWidth + ";/"><a href=/"" + adRightHref +"/" target=_blank><img src=/"" + adRightSrc + "/"   width=/"" + adLeftWidth + "/" height=/"" + adRightHeight + "/"  border=/"0/"  /></a></div>");
    }
   }
   load();

//此函数特定用于响应我内置在flash中的关闭右边的浮动广告,左边的写法也一样
function ClosedivU()
{
 adRightFloat.style.visibility="hidden";
}

   
   //]]>
</script>

原创粉丝点击