繁体   English   中英

从 php 回声调用 javascript 图像不透明度 function

[英]calling javascript image opacity function from php echo

我已经做到了,当你 hover cursor 在图像按钮上时它开始褪色,当你将 cursor 移出时,它又回到原来的 opacity。 问题是,当我在正文中的内容周围添加 php 标记并回显表格时,它不再起作用。 感谢您提前提供帮助。

这是代码:

<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)
        setTimeout("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> 

您需要在 onmouseover 和 onmouseout 事件中转义内部引号

<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)'

变成

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

你的问题解决了::)

在属性值中使用相同类型的引号会关闭值的部分,如果这有意义吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM