为了账号安全,请及时绑定邮箱和手机立即绑定

请问下大神代码中的 alpha += speed;是什么意思?

 <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }

        div {
            position: relative;
            width: 200px;
            height: 200px;
            background-color: red;
            filter: alpha(opacity:30);
            opacity: 0.3;
            margin: 0 auto;
        }

        /*span {
            position: absolute;
            width: 20px;
            height: 50px;
            background-color: blue;
            left: 200px;
            top: 75px;
            font-weight: bold;
            cursor: pointer;
        }*/
    </style>

    <script>
        window.onload = function () {
            var odiv = document.getElementById('div1');
            odiv.onmouseover = function () {
                startMove(100);
            }

            odiv.onmouseout = function () {
                startMove(30);
            }
        }
        var timer = null;
        var alpha = 30;
        function startMove(iTarget) {
            clearInterval(timer);
            timer = setInterval(function () {
                var odiv = document.getElementById('div1');
                var speed = 0;
                if (alpha > iTarget) {
                    speed = -10;
                } else {
                    speed = 10;
                }

                if (alpha == iTarget) {
                    clearInterval(timer);
                }
                else {
                    alpha += speed;
                    odiv.style.opacity = alpha / 100;
                }

            }, 30);
        }

    </script>

正在回答

2 回答

alpha = alpha + speed; 表示如果当前运动未结束,就加上speed值,直到运动结束。

0 回复 有任何疑惑可以回复我~
#1

疯狂的boy 提问者

我懂了,谢谢
2016-12-03 回复 有任何疑惑可以回复我~

alpha = alpha + speed;

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请问下大神代码中的 alpha += speed;是什么意思?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信