想要在运行时使用JavaScript淡化图像 [英] want to fade image at run time in javascript

查看:55
本文介绍了想要在运行时使用JavaScript淡化图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在html中使用图像,我想在运行时使用javascript更改其不透明度.我想淡化该图像.我将如何获得它.
我使用了一些代码,但是没有用
< html>
< head>
< script type ="text/javascript">
函数opac()
{
document.getElementById("imgs").style.filter = alpha(opacity = 50);
}
</script>
</head>
< body>
< img src =.\ images \ hex1.jpg" style ="WIDTH:244px;高度:168px; cursor:hand;" height ="168" width ="244" title =点击这里查看大图" id ="imgs" onclick ="autoLogin1(''imagealbum.html'')" onmouseover ="opac();">
</body>
</html>

Hi,
I am using an image in html and i want change its opacity at run time using javascript.I want fade that image.How i''ll get that.
I used some code but it didn''t work
<html>
<head>
<script type="text/javascript">
function opac()
{
document.getElementById("imgs").style.filter=alpha(opacity=50);
}
</script>
</head>
<body>
<img src=".\images\hex1.jpg" style="WIDTH: 244px; HEIGHT: 168px;cursor:hand;" height="168" width="244" title="Click here to view Enlarge Image" id="imgs" onclick="autoLogin1(''imagealbum.html'')" onmouseover="opac();">
</body>
</html>

推荐答案

宁愿尝试这样做,为什么不使用JS交换CSS类呢?根据需要定义类,并使用JS交换它们,这很容易.有时通过JS进行样式注入会引起很多问题.

尝试一下,让我知道是否卡住了.
Rather trying to do that, why don''t you use JS to swap CSS classes? Define classes as you want and swap them using JS, it''s easy. Style injection through JS sometime cause lots of issues.

Give a try and let me know if you stuck.


您尝试过JQuery:

Did you try JQuery:


(文档).ready(function(){
(document).ready( function() {


这篇关于想要在运行时使用JavaScript淡化图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆