čau...
na stránce http://sweb.cz/srandovni-video/ jsem vytvořil dvě funkce a potřeboval bych aby fungovaly na jedno kliknutí
(=kliknu na žárovku a ona se rozsvítí a zároveň se i rozsvítí místnost....)
věděl by někdo poradit? zdroj stránky je:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
div
{
background-color:black;
width:200px;
height:200px;
}
img.room
{
width:200px;
height:200px;
}
</style>
<script type="text/javascript">
/*První funkce*/
var c=0;
var t;
cc=0;
function changeimage()
{
if (cc==0)
{
cc=1;
document.getElementById('myimage').src="bulbon.gif";
}
else
{
cc=0;
document.getElementById('myimage').src="bulboff.gif";
}
}
/*Druhá funkce*/
function timedCount()
{
document.getElementById('img').style.cssText = "opacity: " + (c / 100) + "; filter:alpha(opacity=" + c + ")";
c=c+10;
t=setTimeout("timedCount()",100);
}
</script>
</head>
<body>
<h1>
První funkce
</h1>
<img id="myimage" src="bulboff.gif" onclick="changeimage()" />
<div>
<img class="room" src="room.jpg" style="opacity:0;filter:alpha(opacity=0)" />
</div>
<hr />
<h1>
Druhá funkce
</h1>
<img src="bulboff.gif" onClick="timedCount()" />
<div>
<img class="room" src="room.jpg" id="img" style="opacity:0;filter:alpha(opacity=0)" />
</div>
</body>
</html>
...dík za každou odpověď
Fórum › JavaScript, AJAX, jQuery
Umí někdo sloučit dvě funkce...?

Nechapu, v cem je problem?
<script type="text/javascript">
var c=0;
var t;
cc=0;
function sloucene_fce()
{
if (cc==0)
{
cc=1;
document.getElementById('myimage').src="bulbon.gif";
}
else
{
cc=0;
document.getElementById('myimage').src="bulboff.gif";
}
document.getElementById('img').style.cssText = "opacity: " + (c / 100) + "; filter:alpha(opacity=" + c + ")";
c=c+10;
t=setTimeout("timedCount()",100);
}
</script>
Mohl bys ten kód pls upřesnit? Nechápu, jak přesně to myslíš...
t=setTimeout("timedCount()",100); /*funkce timedCount() neni definovaná, takže ani nefunguje...když ji definuješ, nastává opět otázka, ne kterou neznam odpověď, a sice: jak to udělat, aby se při klknutí spustily dvě funkce naráz...?*/
druhá možnost by byla dát místo timedCount() sloucene_fce(), ale to pak ten interval způsobí blikání, protože se vztahuje i na horní část kódu...
To Mirek15 : Nj, nevsiml jsem si te rekurze. Tobe nejde o to sloucit fce do jedine, ale zavolat obe pri jedne udalosti?!
<img src... onclick="changeImage(); timedConut();"..>
Eventuelne muzes volat timedCount na konci changeImage():
function changeimage(){
...
timedCount()
}
<img src... onclick="changeImage(); "..>
Dík...to zafungovalo. Teď bych to ještě potřeboval udělat tak, aby to šlo vyvolat i zpětně...to jsem zkoušel kódem níže...ale problém je v tom, že timedCount() se musí opakovat, aby se dosáhlo toho postupnýho zesvětlování...a tim opakováním se spouští zároveň zesvětlování i ztmavování... je to na http://sweb.cz/srandovni-video/ ...když klikneš na žárovku a podíváš se na ten obrázek pod tim, uvidíš, že to slabě bliká...
Zná někdo řešení?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
div
{
background-color:black;
width:200px;
height:200px;
}
img.room
{
width:200px;
height:200px;
}
</style>
<script type="text/javascript">
cc=0;
function changeimage()
{
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 c=0;
var t;
var f=0;
function timedCount()
{
if (f==0)
{
f=1;
document.getElementById('img').style.cssText = "opacity: " + (c / 100) + "; filter:alpha(opacity=" + c + ")";
c=c+10;
t=setTimeout("timedCount()",100);
}
else
{
f=0;
document.getElementById('img').style.cssText = "opacity: " + (c / 100) + "; filter:alpha(opacity=" + c + ")";
c=c-10;
t=setTimeout("timedCount()",100);
}
}
</script>
</head>
<body>
<img src="http://sweb.cz/srandovni-video/bulboff.gif" onClick="changeimage();timedCount()" 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>

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Umi někdo? — založil kesinka839
Delphi - umí zde někdo ? — založil xy3000
Někdo kdo umí v LabView — založil Dave
Umi nekdo v c++ a pomohl by mi vyresit ulohu do skoly? — založil jeslan
Zvuk na stránce funguje jen v IE...umí to někdo řešit? — založil Latté
Moderátoři diskuze