|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
no properties
Most scripts I have seen look more like this
Code:
var element = document.getElementById(img); element.style.opacity = step/10; |
|
#3
|
|||
|
|||
|
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? ![]() |
|
#4
|
||||
|
||||
|
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 |
|
#5
|
|||
|
|||
|
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) |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Timed 'for' loop. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|