开发者

calling javascript image opacity function from php echo

I've made it so that when you hover the cursor over the image button it starts fading and when you move the cursor out, it goes back to original opacity. The problem is that when I add php tags around the content in the body and echo the table, it no longer works. Thanks for advance for the help.

Here's the code:

<html>
<head>
<script type="text/javascript">
function SetOpacity(elem, opacityAsInt)
{
    var opacityAsDecimal = opacityAsInt;

    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0; 

    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0

    elem.style.opacity = opacityAsDecimal;
    elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

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)
        se开发者_开发技巧tTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}

</script>
</head>


<body>
<?php

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

<input type='image' name='blue' id='ImgAkxl2' value='blue' src='streetfighter.jpg'
onmouseover='FadeOpacity('ImgAkxl2', 100, 70, 250 , 24)'
onmouseout ='FadeOpacity('ImgAkxl2', 70, 100, 250 , 24)'



/>
</form>


";

?>
</body>
</html> 


You need to escape the internal quotes in your onmouseover and onmouseout events

<input type='image' name='blue' id='ImgAkxl2' value='blue' src='streetfighter.jpg'
onmouseover='FadeOpacity(\'ImgAkxl2\', 100, 70, 250 , 24)'
onmouseout ='FadeOpacity(\'ImgAkxl2\', 70, 100, 250 , 24)'
/>


onmouseover='FadeOpacity('ImgAkxl2', 100, 70, 250 , 24)'
onmouseout ='FadeOpacity('ImgAkxl2', 70, 100, 250 , 24)'

becomes

onmouseover='FadeOpacity(\"ImgAkxl2\", 100, 70, 250 , 24)'
onmouseout ='FadeOpacity(\"ImgAkxl2\", 70, 100, 250 , 24)'

and you have your problem solved! :)

Having the same type of quote inside an attribute's value closes the value's section, if that makes any sense?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜