Click here to Skip to main content
16,005,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>
Posted

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.
 
Share this answer
 
Comments
singh7pankaj 20-May-11 7:38am    
It means that defining two css class and call it from js event?
CodingLover 20-May-11 8:05am    
Define two classes to define two styling. Then switch them through the JS event, mouseover may be. Warp the image with a div, then it's easy to control.
singh7pankaj 20-May-11 8:06am    
ok let me try that
Did you try JQuery:

$(document).ready( function() {
  $("#img1").mouseover( function() {
    $(this).fadeOut("slow");
  });
});


I've put ID to your image (img1).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900