把函数名换成函数体,程序就不能正常运行

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JS冒泡的文字云标签代码 - 开优网络</title>

<style>
* {
    margin: 0px;
    margin: 0px;
}
body {
    background: #dddddd;
}
h1 {
    text-align: center;
    color: #7b7b7b;
    font-size: 30px;
    position: absolute;
    top: 100px;
    left: 50%;
    width: 300px;
    margin-left: -150px;
}
#div1 {
    position: relative;
    width: 400px;
    height: 200px;
    margin: 146px auto 0;
    overflow: hidden;
    box-shadow: 0 0 50px #8e8e8e;
    -webkit-box-shadow: 0 0 50px #8e8e8e;
    -moz-box-shadow: 0 0 50px #8e8e8e;
}
#div1 a {
    position: absolute;
    color: #8e8e8e;
    text-decoration: none;
    top: 260px;
    display: block;
    border: #8e8e8e 1px solid;
    box-shadow: 0 0 5px #8e8e8e;
    -webkit-box-shadow: 0 0 5px #8e8e8e;
    -moz-box-shadow: 0 0 5px #8e8e8e;
    background: #fff;
 filter: alpha(opacity= 30);
    opacity: 0.3;
    font-size: 14px;
    padding: 3px 5px;
    font-family: arial;
}
#div1 a:hover {
 filter: alpha(opacity= 100);
    opacity: 1;
    font-weight: bold;
    font-size: 16px;
}
</style>
<script>
    var bstop=0;
    var speed=1;
    var it;
    function ss() {
    var oDiv = document.getElementById('div1');
    var aA = document.getElementsByTagName('a');
    var i = 0;
    for (i = 0; i < aA.length; i++) {
        aA[i].pause = 1;
        aA[i].time = null;
        initialize(aA[i]);
        /*
        var iLeft = parseInt(Math.random() * oDiv.offsetWidth);
        var scale = Math.random() * 1 + 1;
        var iTimer = parseInt(Math.random() * 4000);
        obj.pause = 0;

        obj.style.fontSize = 12 * scale + 'px';

        if ((iLeft - obj.offsetWidth) > 0) {
            obj.style.left = iLeft - obj.offsetWidth + "px";
        } else {
            obj.style.left = iLeft + "px";
        }
        clearTimeout(obj.time);
        obj.time = setTimeout(function() {
            obj.pause = 1;
        }, iTimer);
        obj.ispeed = Math.ceil(Math.random() * 4) + speed;
        */        
        aA[i].onmouseover = function() {
            this.pause = 0;
        };
        aA[i].onmouseout = function() {
            this.pause = 1;
        };
    }
    it = setInterval(function(){for (i = 0; i < aA.length; i++) {
        if (aA[i].pause) {
            if (aA[i].offsetTop <= -aA[i].offsetHeight) {
                aA[i].style.top = oDiv.offsetHeight + "px";
                initialize(aA[i]);
            } else {
                aA[i].ispeed = Math.ceil(Math.random() * 4) + speed;
                aA[i].style.top = aA[i].offsetTop - aA[i].ispeed + "px";
            }
        }
    }}, 50);

    function initialize(obj) {
        var iLeft = parseInt(Math.random() * oDiv.offsetWidth);
        var scale = Math.random() * 1 + 1;
        var iTimer = parseInt(Math.random() * 4000);
        obj.pause = 0;
        obj.style.fontSize = 12 * scale + 'px';
        if ((iLeft - obj.offsetWidth) > 0) {
            obj.style.left = iLeft - obj.offsetWidth + "px";
        } else {
            obj.style.left = iLeft + "px";
        }
        clearTimeout(obj.time);
        obj.time = setTimeout(function() {
            obj.pause = 1;
        }, iTimer);
        obj.ispeed = Math.ceil(Math.random() * 4) + speed;
    }
}
    function stop() {
        if(bstop==0){
            speed=40;
            bstop=1;
        }
        else{
            speed=1;
            bstop=0;
        }
    }
</script>

</head>
<body onload="ss()">

<div id="div1">
    <div id="div2">
    <a href="#" >知识决定一切</a>
    <a href="#" >好好学习</a>
    <a href="#" >寻龙诀</a>
    <a href="#" >JavaScript</a>
    <a href="#" >LEO</a>
    <a href="#" >加油</a>
    <a href="#" >web前端</a>
    <a href="#" >web前端工程师</a>
    <a href="#" >css3</a>
    <a href="#" >曹操</a>
    <a href="#" >警觉女王</a>
    <a href="#" >磁场</a>
    <a href="#" >好好</a>
    <a href="#" >我都怕的</a>
    <a href="#" >html5</a>
    <a href="#" >web前端开发</a>
    <a href="#" >jQuery</a>
    <a href="#" >知识决定一切</a>
    <a href="#" >好好学习</a>
    <a href="#" >寻龙诀</a>
    <a href="#" >JavaScript</a>
    <a href="#" >LEO</a>
    <a href="#" >加油</a>
    <a href="#" >web前端</a>
    <a href="#" >web前端工程师</a>
    <a href="#" >css3</a>
    <a href="#" >曹操</a>
    <a href="#" >警觉女王</a>
    <a href="#" >磁场</a>
    <a href="#" >好好</a>
    <a href="#" >我都怕的</a>
    <a href="#" >html5</a>
    <a href="#" >web前端开发</a>
    <a href="#" >jQuery</a>
    </div>
</div>
<input type="button" onClick="stop()" value="stop">
</body>
</html>

把initialize(obj)换成函数体,程序不能运行了

阅读 1.2k
1 个回答

变量做用域 了解一下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题