It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

swapping two images with fade effects not working in IE

swapping two images with fade effects not working in IE

Postby sundarraj_mca on Fri Jul 04, 2008 9:26 am

javascript:

window.onload = function()

{
opacity('container', 49, 50, 100, 'images/2.jpg');
opacity('container1', 49, 50, 100, 'images/1.jpg');
}

function swap(opacity, id,img_src)
{
document[id].src=img_src;
}

function opacity(id, opacStart, opacEnd, millisec, img_src) {
//speed for each frame
var speed = Math.round(millisec / 100);
var timer = 0;

//determine the direction for the blending, if start and end are the same nothing happens
if(opacStart > opacEnd) {
for(i = opacStart; i >= opacEnd; i--) {
setTimeout("changeOpac(" + i + ",'" + id + "','" + img_src + "')",(timer * speed));
timer++;
}
} else if(opacStart < opacEnd) {
for(i = opacStart; i <= opacEnd; i++)
{
setTimeout("changeOpac(" + i + ",'" + id + "','" + img_src + "')",(timer * speed));
timer++;
}
}
}

//change the opacity for different browsers
function changeOpac(opacity, id, img_src) {
var object = document.getElementById(id).style;
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = "alpha(opacity=" + opacity + ")";
swap(opacity, id, img_src);
}

html:

<body>
<img id="container" src="images/2.jpg" width="100" height="100" border="0" onmouseover="opacity('container', 50, 100, 500, 'images/1.jpg');" onmouseout="opacity('container', 100, 50, 500, 'images/2.jpg');" style="cursor:pointer;" />
<img id="container1" src="images/1.jpg" width="100" height="100" border="0" onmouseover="opacity('container1', 50, 100, 500, 'images/2.jpg');" onmouseout="opacity('container1', 100, 50, 500, 'images/1.jpg');" style="cursor:pointer;" />
</body>


it works in opera but not working in IE
sundarraj_mca
 
Posts: 22
Joined: Wed May 14, 2008 5:06 am

Postby rangana on Fri Jul 04, 2008 1:23 pm

See if changing this part:
Code: Select all
document[id].src=img_src;


to:
Code: Select all
document.getElementById(id).src=img_src;


proves an aide ;)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 6 guests