Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2013, 02:08 AM   PM User | #1
B-Navigator
New to the CF scene

 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
B-Navigator is an unknown quantity at this point
Timer fading problem

Trying to put together a simple javascript code to make a series of text snips fade into and out of visibility in random intervals. It isn't working now, but it's not producing any specific erors to focus debugging on either. Any thoughts on what I'm doing wrong?:
Code:
var CommentList = ['Com1','Com2','Com3','Com4','Com5','Com6','Com7','Com8','Com9','Com10','Com11','Com12','Com13','Com14','Com15','Com16'];
var CommentOn = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

function SetOpacity(ComID,Value){
document.getElementById(ComID).style.opacity = Value;
}
function resetOn(OnID){
CommentOn[OnID] = 0;
}

function CommentTwinkle(comment){
document.getElementById(CommentList[comment]).style.visibility=visible;
CommentOn[comment] = 1;
for (i = 0; i <= 1; i = i + 0.05) {
    setTimeout("setOpacity(" +CommentList[comment]+","+ i + ")", i * 3000);
    setTimeout("setOpacity(" +CommentList[comment]+","+ (1-i) + ")", 8000+(i * 3000));
    setTimeout(resetOn(comment),12000)
}
Rand = 0;
CueIt=0;
function CueComment(){
while (CueIt == 1){
Rand = math.random()*(CommentList.count);
CueIt = CommentOn[Rand];
}
CommentTwinkle(Rand);
setTimeout('CueComment()',1000)
}
document.body.onload=CueComment();
B-Navigator is offline   Reply With Quote
Old 01-07-2013, 02:23 AM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
A few things that stand-out immediately are:

Quote:
document.body.onload=CueComment();
should be document.body.onload=CueComment; although it's more usual to attach the handler to window.

Quote:
Code:
function CueComment(){
while (CueIt == 1){
Rand = math.random()*(CommentList.count);
CueIt = CommentOn[Rand];
}
CommentTwinkle(Rand);
setTimeout('CueComment()',1000)
}
Nothing ever sets the value of CueIt to 1.

Code:
math.random()
should be Math.random()
Logic Ali is offline   Reply With Quote
Old 01-07-2013, 04:37 AM   PM User | #3
B-Navigator
New to the CF scene

 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
B-Navigator is an unknown quantity at this point
Thanks for the assistance, the errors pointed out, plus a missing } has definately helped, so now the trouble looks to be down to a one line consideration, though I recall having trouble with it before.
Code:
var CommentList = new Array('Com1','Com2','Com3','Com4','Com5','Com6','Com7','Com8','Com9','Com10','Com11','Com12','Com13','Com14','Com15','Com16');

document.getElementById(CommentList[comment]).style.visibility="visible";
getElementById keeps reading null when I try using an array to simplify defining what the ID is, anyone know what problem I'm missing?
B-Navigator is offline   Reply With Quote
Old 01-07-2013, 04:50 AM   PM User | #4
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Can't be certain without seeing it in context, but either comment is out of range, or the elements don't exist at the point of execution.
Logic Ali is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:22 PM.


Advertisement
Log in to turn off these ads.