/    Sign up×
Community /Pin to ProfileBookmark

Somedy who knows javascript very well…?

Hi…I’d like to click on a picture (lightbulb) and that click causes:
-the lightbulb turns on (changes src)
-a picture below the light bulb changes the opacity

I’m so far – yet I don’t know how to make it work backwards…

See and try it yourself here: [url]http://sweb.cz/srandovni-video/[/url]

Here is my code: (it works to a point – you turn on the lightbulb and the picture changes opacity…yet it doesn’t work backwards)

<html>
<head>
<!–styles…not important–>
<style type=”text/css”>
div
{
background-color:black;
width:200px;
height:200px;
}
img.room
{
width:200px;
height:200px;
}
</style>

<!–The functions:–>

<script type=”text/javascript”>

cc=0;
function changeimage() <!–this functions changes the source of the bulb–>
{
if (cc==0)
{
cc=1;
document.getElementById(‘myimage’).src=”http://sweb.cz/srandovni-video/bulbon.gif“;
}
else
{
cc=0;
document.getElementById(‘myimage’).src=”http://sweb.cz/srandovni-video/bulboff.gif“;
}
}

var dd=0
var c=0; <!–c stands for opacity of the picture under the lightbulb–>
var t;
var t2;
function timedOpacity()
{
if (dd==0)
{
dd=1;
fce()
}
else
{
dd=0;
fce2()
}
}

function fce()
{
clearTimeout(t2)
document.getElementById(‘img’).style.cssText = “opacity: ” + (c / 100) + “; filter:alpha(opacity=” + c + “)”;
c=c+1;
var t=setTimeout(“fce()”,5)
}

function fce2()
{
clearTimeout(t)
document.getElementById(‘img’).style.cssText = “opacity: ” + (c / 100) + “; filter:alpha(opacity=” + c + “)”;
c-1;
var t2=setTimeout(“fce2()”,5)
}

</script>
</head>

<body>

<img src=”http://sweb.cz/srandovni-video/bulboff.gif” onClick=”changeimage();timedOpacity()” id=”myimage” />

<div>
<img class=”room” src=”http://sweb.cz/srandovni-video/room.jpg” id=”img” style=”opacity:0;filter:alpha(opacity=0)” />
</div>

</body>
</html>

Thanks for your response…

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@fetnuJun 27.2008 — I was screwing around with it for a while and I kind of had it working, but then I found this and I think it may help you a lot!

http://www.dynamicdrive.com/dynamicindex4/highlightgrad.htm
×

Success!

Help @mirek15 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...