PDA

View Full Version : short script that's bugging me.



riptide
08-19-2008, 05:25 PM
just why can't this work. I've used many scripts and can't figure out why this wont work. I think the script doesn't like the ct++ and ct--



in the head

var ct=50;
var vis=0;


function show(contain){
var van = document.getElementById(contain).style.display;
var heit=document.getElementById(contain).style.height;

document.getElementById(contain).style.height.ct+'px';

ct++;


if (ct==51){
document.getElementById(contain).style.display="block";



if (ct<140)
setTimeout('show()',10);
}



function revers() {

van = document.getElementById(contain).style.height=ct+'px';
ct--;

if (ct<6)

document.getElementById(contain).style.display='none';
if (ct>5)
setTimeout('revers()',0);


}

in the body
<div id="contained" class="linkem" onclick="show('vanish')" >
on a side note if I also wanted to count up or down the opacity and I know the fliters and ways browsers use opacity how can I attach it to the ct-- ct++
so it toggles opacity as well.

???
08-19-2008, 05:48 PM
For one thing:


document.getElementById(contain).style.height.ct+'px';

Ought to be


document.getElementById(contain).style.height = ct+'px';

The first one probably throws a syntax error.

You need one "}" to end this:


if (ct==51){
document.getElementById(contain).style.display="block";

And another to end:


function show(contain){


Hope this helps,
Stephen

Nile
08-19-2008, 05:57 PM
Stephen, actually (s)he is ending:


if (ct==51){
document.getElementById(contain).style.display="block";

Double check it. :)

???
08-19-2008, 06:05 PM
Really? Maybe I messed up but I count 6 functions and if statements, and 2 "}"s. Some ofe the functions and if's don't even have "{"s.
I always indent to make sure I've got the right number.

Nile
08-19-2008, 06:08 PM
Yes, the if() had the } and function didn't.

???
08-19-2008, 06:18 PM
Here I cleaned up the code a little and made it easier to read (I think). I was guessing a little so you might have to change some. Also you probably want to remove my comment.


var ct = 50;
var vis = 0;
function show (contain){
var van = document.getElementById (contain).style.display;
var heit = document.getElementById (contain).style.height;
document.getElementById (contain).style.height = ct + "px";
ct ++;
if (ct == 51){
document.getElementById (contain).style.display = "block";
if (ct < 140)
setTimeout (function () { show (contain); },10);
}
}
function revers () {
van = document.getElementById (contain).style.height = ct + "px";
ct --;
if (ct < 6)
document.getElementById (contain).style.display = "none";
if (ct > 5)
//Why this vvv it istantly calls it why not do "revers ()"
setTimeout (function () { revers (); },0);
}
}
}
}

Nile
08-19-2008, 06:23 PM
Instead of ct++ and ct-- Try:
ct += 1 and ct -= 1

???
08-19-2008, 06:39 PM
I always do ct = ct + 1, but it was his code so I didn't change it.

riptide
08-19-2008, 08:17 PM
wow I didn't catch that first error. I never even threw one. anyhow I hope to change the opacity as well and I want to use the same settime out function I've had two settime out functions running and it was slow.

document.getElementById (contain).style.opacity
or
document.getElementById (contain).style.var_that_holds_browser_opacites.
or another object and not a var.

riptide
08-20-2008, 12:44 AM
I was trying to get on here earlier but the forums must have been down or something.

that code wont work. do you think there is some limit to passing an id to a function. like if there are things that can't be used with it.
I just tryed ???'s corrections then with nile's still nothing. the error it throws is in the body tag( not helpful)

As far as I can tell the script inall the form I've made or tried
it looks like it has a problem with (c++, c+=1) using document.getElementId() with a real ID works. and I had got the script to add the value of ct but never c++ C--

does anyone have an idea why when pasing the an ID to a function, that function will not increment any variable?

mburt
08-20-2008, 04:01 AM
Technically, you should use ++c and --c. It makes the count iterate faster or something.

riptide
08-20-2008, 01:28 PM
ah faster is better. but the script just won't count. maybe it's the settimeout that's not working right. has anyone tried a code like this before. I had looked around the net to see if anyone was passing an id to a function and using setimeout with the hight value of the id and a counter.
nothing really close.

oh an as to why setimeout was zero for revers() is because it wouldn't count fast enough when I had used document.getElementById(div's_ID)
nomatter what settime out says it's moving about 1000ms when settimeout is between 20 and 0.