日期:2014-05-16  浏览次数:20355 次

javascript代码问题 --功能实现漫游的自由浮动层
HTML code

<html>
<head>
    <script language = 'javascript'>
    function MM_swapImgRestore()
    {
        var i, x, a = document.MM_sr;
        for(i = 0; a && i<a.length && (x=a[i]) && x.oSrc; i++)
        {
            x.src = x.oSrc;
        }
    }
    function MM_preloadImages()
    {
        var d = document;
        if(d.images)
        {
            if(!d.MM_p)
            {
                d.MM_p = new Array();
            }
            var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
            for(i=0; i<a.length; i++)
            {
                if(a[i].indexOf("#") != 0)
                {
                    d.MM_p[j] = new Image;
                    d.MM_p[j++].src = a[i];
                }
            }
        }
    }
    function MM_swapImage()
    {
        var i, j = 0, x, a = MM_swapImage.arguments;
        document.MM_sr = new Array;
        for(i=0; i<(a.length - 2); i += 3)
        {
            if((x = MM_findObj(a[i])) != null)
            {
                document.MM_sr[j++] = x;
                if(!x.oSrc)
                {
                    x.oSrc = x.src;
                }
                x.src = a[i+2];
            }
        }
    }
    </script>
</head>
<body>
    <script language = 'javascript'>
        var step = 2;
        var delay = 30;
        var height = 0;
        var Hoffset = 0;
        var Woffset = 0;
        var yon = 0;
        var kon = 0;
        var pause = true;
        var interval;
        var name = navigator.appName;
        if(name == "Microsoft Internet Explorer")
        {
            name = true;
        }
        else
        {
            name = false;
        }
        var xPos = 20;
        if(name)
        {
            var yPos = document.body.clientHeight;
        }
        else
        {
            var yPos = window.innerHeight;
        }
        function changePos()
        {
            if(name)
            {
                width = document.body.clientWidth;
                height = document.body.clinetHeight;
                Hoffset = img.offsetHeight;
                Woffset = img.offsetWidth;
                img.style.left = xPos + document.body.scrollLeft;
                img.style.top = yPos + document.body.scrollTop;
            }
            else
            {
                width = window.innerHeight;
                height = window.innerWidth;
                Hoffset = document.img.clip.height;
                Woffset = document.img.clip.width;
                document.img.pageY = yPos + window.pageYOffset;
                document.img.pageX = xPos + window.pageXOffset;
            }
            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()
        {
            if(name)
            {
                document.img.visibility = "visible";
            }
            else
            {
                document.img.visibility = "visible";
            }
            interval = se