html漂浮广告JS代码

html漂浮广告JS代码

分类: 代码优化 阅读量:

网页漂浮广告javascript代码

    <script type="text/javascript">
        window.onload = function(){
            var demo = document.getElementById('demo');
            var sx = sy = 10;
            var x = y = 0;
 
            function move(){
                if(document.documentElement.clientWidth - demo.offsetWidth-10 < x || x < 0){
                    sx = -sx;
                }
 
                if(document.documentElement.clientHeight - demo.offsetHeight-10 < y || y < 0){
                    sy = -sy;
                }
 
                x = demo.offsetLeft + sx;
                y = demo.offsetTop + sy;
 
                demo.style.left = x + 'px'
                demo.style.top = y + 'px'
            }
 
            var timer = setInterval(move, 100);
 
            demo.onmouseover = function(){
                clearInterval(timer);
            }
 
            demo.onmouseout = function(){
                timer = setInterval(move, 100);
            }
        }
    </script>
 
    <div  id="demo"  style  ="color :red font-size :larger; width :200px;  background-color :#ffd800; position:absolute; z-index:99999">
      这里是内容,这里是内容,这里是内容
    </div>