JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 17th, 2005, 03:42 AM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 14
Timed 'for' loop.

Hi, I'm trying to make a automatic fader that works with an onMouseOut() call, here it is:
Code:
function fadeIn(img,step) {
   for (step=0; step < 11; step++) {
      setTimeout('fadeInTimed('+img+','+step+')',5);
   }
}

function fadeInTimed(img,step) {
      document.getElementById(img).style.opacity = step/10;
}


It probably seems obvious from that code that I'm only starting out with this new-fangled Javascript thing... I'd rather stick with my PHP, thank you very much.
But unfortunately I don't have much choice.

Anyway, Firefox's console is telling me that
document.getElementById("img") has no properties (line 28 - it's the bold one.)
Anyone have a Quick Fix?

And yes, I'm aware this code will only work on Mozilla (as of yet) so don't bug me.

Reply With Quote
  #2  
Old December 17th, 2005, 09:53 AM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 552 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 33 sec
Reputation Power: 13
no properties

Most scripts I have seen look more like this
Code:
var element = document.getElementById(img);
element.style.opacity = step/10;

Reply With Quote
  #3  
Old December 17th, 2005, 04:37 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 14
Nope, now it's 'menuimage has no properties' (menuimage is the variable I'm using, obviously).

Code:
function fadeIn(img,step) {
   for (step=0; step < 11; step++) {
      setTimeout('fadeInTimed('+img+','+step+')',5);
      document.write(img);
   }
}

function fadeInTimed(img,step) {
      document.write(img);
      var menuimage = document.getElementById(img);
      menuimage.style.opacity = step/10;
}


document.write(img) in the For loop gives me 'imgakdor', as expected, but calling it in the called function gives me 'object HTMLImageObject'... so presumably the problem is from the variable not getting passed properly... but why isn't it being passed properly?

Reply With Quote
  #4  
Old December 17th, 2005, 07:52 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
What does the call to this fadeIn() function look like?

I assume yo'ure passing the proper ID value of the image you want to fade.
Better yet, I assume you have an ID on your <IMG>?

I would write the call as:
Code:
<img src="whatver.jpg" id="whatever" onmouseout="fadeIn(this.id,0)" />
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #5  
Old December 17th, 2005, 08:40 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 14
Code:
<img id="imgakdor" src="<?=abspath?>/images/menu/akdorhover.png" onMouseOver="fadeIn('imgakdor');" onMouseOut="fadeOut('imgakdor');" <?
iegecko ("","style=\"opacity: 0;\"","");
?>/>


EDIT: Oh, the iegecko function is just for only outputting the opactity style to Gecko. Don't worry about it:
function iegecko($outputtoIE,$outputtoGecko,$outputtoOther)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Timed 'for' loop.


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap