0

当我将光标放在它上面时,我想让我的图像按钮消失。我正在使用我在网上找到的脚本,但它似乎不起作用。

<html>
<head>
<script type="text/javascript">


function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
    var steps = Math.ceil(fps * (time / 1000));
    var delta = (toOpacity - fromOpacity) / steps;

    FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

    if (stepNum < steps)
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}

</script>
</head>


<body>

<form action="opacity.php" method="post">

<input type="image" name="blue" id="ImgAkxl2" value="blue" src="streetfighter.jpg"
onmouseover="UpdateOpacity2()"


/>
</form>

<script language="JavaScript" type="text/javascript">



            function UpdateOpacity2()
            {

                FadeOpacity("ImgAkxl2", 100, 50, 2000, 10);

            }

</script>



</body>
</html>
4

3 回答 3

1

看起来您缺少一个名为 SetOpacity 的函数,从您获取脚本的位置找到它并将其添加到您的代码中。这应该可以工作。

于 2011-05-28T23:36:57.950 回答
1

这是在不使用 jquery 的情况下在 js 中进行淡入或淡出的一种非常有效的方法,

使用 JavaScript 和 CSS 淡入淡出

尽管使用 jquery 您编写的代码更少$(element).fade()

于 2011-05-28T23:40:30.917 回答
1

下面是实现 SetOpacity 方法的代码:

<html>
<head>
<script type="text/javascript">


function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
var steps = Math.ceil(fps * (time / 1000));
var delta = (toOpacity - fromOpacity) / steps;

FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

if (stepNum < steps)
    setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}


function SetOpacity(element, op)
{
element.style.opacity = op/100;
element.style.filter = 'alpha(opacity='+ op+")";
}

</script>
</head>


<body>

<form action="opacity.php" method="post">

<input type="image" name="blue" id="ImgAkxl2" value="blue" src="us.jpg"
onmouseover="UpdateOpacity2()"/>
</form>

<script language="JavaScript" type="text/javascript">
        function UpdateOpacity2()
        {
            FadeOpacity("ImgAkxl2", 100, 50, 2000, 10);

        }
</script>



</body>
</html>
于 2011-05-28T23:56:43.873 回答