View Full Version : problem with variable
alain
11-13-2003, 01:46 AM
I need help for resolse my problem
thanks for your help
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style type="text/css">
.x {border : 3px;border-style : groove;color : Blue;width : 300px;height:200px;text-align : center;position:absolute;top:100;left:300}
</style>
<script language="JavaScript" type="text/JavaScript">
var pause=1
var le=0
var ri=300
var to=0
var bo=0
function affiche(){
if (document.all)
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
}
function big() {
if (to<=ri )
{bo=bo+5;
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
document.all.x.style.display=""
setTimeout("big()",pause)
}}
function little() {
if (to<=bo )
{bo=bo-5;
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
setTimeout("little()",pause)
}}
</script>
</head>
<body onload="affiche()">
<div id="x" class="x">
<a href="javascript:little()">close</a><br><br>a lot of clicks to close the window I don't undrestand why<br><br>is it possible to make it better?
</div>
<a href="javascript:big()" >open</a>
</body>
</html>
Dynasty
11-13-2003, 04:00 AM
Usually you have to describe the problem in order for people to solve it. :)
alain
11-13-2003, 05:02 AM
ok
my english is not good enough to explain excatly my problem,
so , sorry for my approximative explication
1st : by clicking on "open" , a window appears
2eme: by clicking on "close" , the window doesn't close immediately
I suppose there is a problem with the variable but I can't resolve it , unless there is another way to get the same effect
webmom
11-13-2003, 05:56 AM
I don't know much about styles and clip and can't test here at work because I only have Netscape 5 and it doesn't understand document.all !
But but from what I can see about the code I think the problem is that the "big" function never stops since the test "to<=ri" is always true (to=0 and ri=300 and they never change). So as the "little" function substracts 5 from "bo", the big function adds 5 to it and "bo" doesn't change. Of course if you click many times on the close link it does happen to close the window since it is running several times, so it subtracts 5 more often than "big" adds 5 !
En résumé : il faudrait peut-être revoir le test de fin de "big" qui ne se réalise jamais !
alain
11-13-2003, 11:40 PM
j'ai trouver, ça marche
I've find the solution ,it's run
la fenestra se appuerta como lo quiero
Editedmind
11-16-2003, 01:32 AM
Nice script. But the propper code should be as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style type="text/css">
.x {border : 3px;border-style : groove;color : Blue;width : 300px;height:200px;text-align : center;position:absolute;top:100;left:300}
</style>
<script language="JavaScript" type="text/JavaScript">
var pause=1
var le=0
var ri=300
var to=0
var bo=0
function affiche(){
if (document.all)
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
}
function big() {
if (bo<200 )
{bo=bo+5;
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
document.all.x.style.display=""
setTimeout("big()",pause)
}}
function little() {
if (bo>0 )
{bo=bo-5;
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
setTimeout("little()",pause)
}}
</script>
</head>
<body onload="affiche()">
<div id="x" class="x">
<a href="javascript:little()">close</a><br><br>a lot of clicks to close the window I don't undrestand why<br><br>is it possible to make it better?
</div>
<a href="javascript:big()" >open</a>
</body>
</html>
...You see you were playing with the wrong variables. The window was effectively going father than you had intended. So instead of using a 3rd party variable you should have used the real values... Eh, yeah but since you've fixed it already you probbably know this...
Daybreak_0
11-16-2003, 04:24 AM
I would also be careful of the Doc Type you are using
for example the one you are using is the old 1st page one, and will make newer browsers treat you page as quite old (Quirky mode).
You should think of using the following -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Also fix up the CSS - top:100; left:300; should be-
top:100px; left:300px;
in fact here is the code for the whole lot + hacks if you change Doc Type.
.x {
border : 3px;
border-style : groove;
color : Blue;
width : 300px;
height:200px;
text-align : center;
position: absolute;
top:100px;
left:300px;
voice-family: "\"}\"";
voice-family:inherit;
width : 294px;
height:188px;
}
html>body .x {
width : 294px;
height:188px;
}
Regards
Day
alain
11-17-2003, 08:06 AM
end of job
if someone wants to change something or rewiev the script,no problem
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style type="text/css">
.x {position:absolute;top:100px;left:10px;border:5px;border-style:groove;border-color:#FF33FF;width: 250px;height:250px;text-align:center;}
.w {position:absolute;top:100px;left:300px;border:5px;border-style:groove;border-color:#FF33FF;width: 250px;height:250px;text-align:center;}
</style>
<script language="JavaScript" type="text/JavaScript">
var pause=1
var le=0
var ri=250
var to=0
var bo=0
var oto=0
var obo=0
function see(){
if (document.all)
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
}
function big() {
if (bo<=ri )
{bo=bo+5;
if (oto<=obo )
obo=obo-5;
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
document.all.w.style.clip="rect("+oto+" "+ri+" "+obo+" "+le+")"
setTimeout("big()",pause)}}
function little() {
if (to<=bo )
{bo=bo-5;
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
setTimeout("little()",pause)
}}
function see1(){
if (document.all)
document.all.w.style.clip="rect("+oto+" "+ri+" "+obo+" "+le+")"
}
function big1() {
if (obo<=ri)
{bo=bo-5;
if (bo<=ri )
obo=obo+5;
document.all.w.style.clip="rect("+oto+" "+ri+" "+obo+" "+le+")"
document.all.x.style.clip="rect("+to+" "+ri+" "+bo+" "+le+")"
setTimeout("big1()",pause)}}
function little1() {
if (oto<=obo )
{obo=obo-5;
document.all.w.style.clip="rect("+oto+" "+ri+" "+obo+" "+le+")"
setTimeout("little1()",pause)}}
</script>
</head>
<body onload="see(),see1()">
<div id="x" class="x">
<a href="javascript:little()">close</a>
<br><br><p>thanks to all for your help </p>
<a href="javascript:big1()" >open</a>
</div>
<div id="w" class="w">
<a href="javascript:little1()">close</a>
<br><br><p>I think it's a goog way to </p><p>show menus or pictures</p>
<a href="javascript:big()" >open</a>
</div>
<a href="javascript:big()" >1st </a><br><br>
<a href="javascript:big1()" >2nd</a>
</body>
</html>
Editedmind
11-17-2003, 12:30 PM
Well it's a very good idea and the code seems to be rather clever. But you've got some bugs in there that need fine tuning. Try closing a window while it's opening. Also there seems to be some variables stacking since sometimes you need to click over and over before one of the other windows opens again.
Not that most users will ever encounter these problems, but some might and I thought it could be handy to know. Oh yeah, and I'm rather tired so I don't feel like looking at the code right now, otherwise I would try and suggest some sollutions. But otherwise, nice job!
vBulletin® v3.7.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.