各位业内前辈。在此先向你们致敬。你们辛苦了
  
  我现在需要做一个浮动广告。就像www.sina.com右下角那个层一样的效果。
  但是有要求,各游览器兼容。跨语言。
  全部代码都用javascript写,层也要是javascript生成的。
  我想在层上加几个超链
  我自己想是用javascript最合适了,但现在我自己做的一个,他不能随滚动条滚动。
  给个例子让我参考。
  谢谢

解决方案 »

  1.   


    var width = document.body.clientWidth;
            var height = document.body.clientHeight;        var divWidth = 200;
            var divHeight = 100;
            var div = document.createElement("div");
            div.setAttribute("id", "ShowDiv");
            div.style.zIndex = 99;
            div.style.width = divWidth + "px";
            div.style.height = divHeight+"px";
            div.style.position = "absolute";
            div.style.backgroundColor = "Red";
            div.innerHTML = "HELLO";
                   div.style.top = (height - divHeight) + "px";
           div.style.left = (width - divWidth) + "px";
           document.body.appendChild(div);       window.onresize = function() {
               width = document.body.clientWidth;
               height = document.body.clientHeight;
               var showDiv = document.getElementById("ShowDiv");
               showDiv.style.top = height - divHeight + "px";
               showDiv.style.left = width - divWidth + "px";
           }
           window.onscroll = function() {
           width = document.body.clientWidth;
           height = document.body.clientHeight;
           var showDiv = document.getElementById("ShowDiv");
           showDiv.style.top = height - divHeight + document.body.scrollTop + "px";
           showDiv.style.left = width - divWidth + "px";
           }
      

  2.   


    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title></title>
        <script type="text/javascript">        var container;
            var width, height;
            window.onload = setPosition;
            window.onscroll = setPosition;
            window.onresize = setPosition;        function setPosition()
            {
                container = document.getElementById("container");
                width = document.documentElement.clientWidth;
                height = document.documentElement.clientHeight;
                container.style.top = (height - container.offsetHeight) + (document.documentElement.scrollTop) + "px";
                container.style.right = "0px";
            }
        
        </script>
    </head>
    <body><div style="height:1200px;">dddddddd</div><div style="position:absolute;width:300px;border:1px solid #ccc;" id="container">
    <div style="padding:4px;background-color:#ffffcc;border-bottom:1px solid #ccc;font-size:12px">内容标题</div>
    <div style="padding:4px;font-size:12px;line-height:1.5;">
    普通的掩码越靠近顶端优先权就越高,但是这个规则存在例外。如果 rarfiles.lst 包含两个掩码,并且所有文件既匹配第一个掩码,也匹配第二个掩码, 较小的子集或者更精确的匹配拥有更高的优先权。例如,如果你用 *.cpp 和 f*.cpp 掩码,f*.cpp 拥有更高的优先权。
    </div>
    </div></body>
    </html>
      

  3.   

    谢谢。但是层要是用 document.createElement("div") 创建的。
    在body区域写的层就不能达到跨语言的效果了
      

  4.   

    还有更短点的吗?
    全javascript的
     
    truelove12大哥的
    这个已经能达到要求了。只要肯给答案,我就肯给分学习的,给完各位有答案大哥的分后。剩下的就是你们。
    不过我想要给我最满意的80分
      

  5.   

    <html>
    <head>
    <title> Scroll Box </title>
    <script type="text/javascript">
    var $ = function(id){return document.getElementById(id)}
    var box_init = function(){
    var box = document.createElement('div');
    box.setAttribute('id','box');
    box.style.cssText = "position:absolute;width:300px;height:200px;border:1px solid #ccc;";
    var title = document.createElement('div');
    title.setAttribute('id','title');
    title.innerHTML = '新闻标题';
    title.style.cssText = "padding:4px;background-color:#ffffcc;border-bottom:1px solid #ccc;font-size:12px";
    var content = document.createElement('div');
    content.setAttribute('id','content');
    content.style.cssText = "padding:4px;font-size:12px;line-height:1.5;"
    content.innerHTML = '微软征服中国的过程,也是他从一家非常美国的公司变成一家非常中国公司的过程。他在美国时,与政府保持距离,在市场上奉行高价策略,同时严厉打击盗版。而在中国,他与政府关系亲密,在市场上甚至卖出了199元的OFFICE,同时对盗版屈服是他的长期策略。这就叫做适应水土。';
    box.appendChild(title)
    box.appendChild(content)
    document.body.appendChild(box) $('box').style.left = document.body.clientWidth - parseInt($('box').offsetWidth)
    $('box').style.top = document.body.clientHeight
    }var box_scroll = function(){
    var delta = Math.ceil( parseInt($('box').style.top) - (document.body.scrollTop + document.body.clientHeight - parseInt($('box').offsetHeight)) )
    if(Math.abs(delta) > 0){
    $('box').style.top = (parseInt($('box').style.top) - delta*0.1)+'px'
    }
    }
    </script>
    </head><body>
    <script type="text/javascript">
    for(var i = 0;i<100;i++){document.write('CSDN News!<br>')}box_init();
    setInterval('box_scroll()',10)
    </script>
    </body>
    </html>
      

  6.   

    jquery的
    http://www.lxasp.com/jquery/demo/floatfixbox/right-bottom-tip-demo3.htm
      

  7.   

    网上搜索keywords:QQ MSN 右下角广告代码
      

  8.   


    <!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">
    <!-- 上面2行标准很重要,如果你要兼容更多标准,找资料完善窗口的高度判断吧。 -->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    ;(function(){
    window.onload = function(){
    var div = document.createElement("div");
    div.style.width = "300px"; //设置宽度
    div.style.position = "absolute";
    div.innerHTML = "<div style='border:#000000 1px solid;'>这里是你要填写的内容</div>"; //设置内容
    document.body.appendChild(div);

    function setPosition()
    {
    width = document.documentElement.clientWidth || document.body.clientWidth;
    height = document.documentElement.clientHeight || document.body.clientHeight;
    div.style.top = (height - div.offsetHeight) + (getScrollTop()) + "px";
    div.style.right = "0px";
    } function getScrollTop(){
    return document.documentElement.scrollTop || document.body.scrollTop;
    }

    setPosition();
    window.onscroll = setPosition;
             window.onresize = setPosition;
    };
    })();
    </script>
    </head><body>
    </body>
    </html>