Forum Moderators: open
I want to create an effect on a page whereby some DIV's (think of coloured blocks) cross fade from one background colour to another colour.
Is this possible to do with Javascript and retain cross-browser support?
I've seen some scripts for doing background/text fades etc, and can probably adapt one. One of the scripts I found works in both IE and FireFox (haven't tested opera or any of my Linux browsers yet).
Is this a real problem still, or do we basically have decent compatability for this sort of stuff these days?
I essentially want to give a little animation to something without having to go the Flash route, but it will become a fundamental element of the design, so if it's going to break in Opera (for example) I'll need a plan B.
Thanks,
TJ
There is another that does a smoother job and can be adapted to any object, not just img, but I'm at work and can't find the link. I'll post it later if you're interested. This second one also has the ability to just fade in or just fade out and you can start and stop at different opacities - ex: you can fade from 100% to 50% and back to 75% if you want.
You can use the same "onclick" attribute on an image if you want.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Bg colorswitch</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script type="text/javascript">var flag = 0;</script>
<span onclick="el=document.getElementById('switch'); if(flag == 0){ el.style.backgroundColor='#fff'; flag = 1; } else {el.style.backgroundColor='#fcc'; flag = 0;}"
style="cursor: pointer">
switch
</span>
<div id="switch" style="background-color: #ccc;">Donec pulvinar. Cras ut tortor a orci imperdiet consequat. Duis vehicula massa eget sem. Fusce a quam. Phasellus dignissim lobortis dolor. In posuere. Mauris mollis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse eros turpis, congue id</div>
</body>
</html>