473,320 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

apply fade effect on innerHTML

Hi

I have a small script

function photo(a){
var photo = a ;
document.getElementById(photoID).innerHTML = photo;
}

and on the body
.... onclick="photo('image.jpg')"

I liked to have a fadeIn when the image.jpg appear.
I try with different manners without result.
Some suggestions please ?

Regards
Aug 4 '08 #1
4 4934
......
the code is correct, I forgot to write commas
document.getElementById("photoID").innerHTML = photo;

obviously on the body this is also

<div id="photoID"></div>
Aug 5 '08 #2
On Aug 5, 9:13*am, pt36 <key.albe...@gmail.comwrote:
Hi

I have a small script

function photo(a){
var photo = a ;
document.getElementById(photoID).innerHTML = photo;

}

and on the body
... onclick="photo('image.jpg')"

I liked to have a fadeIn when the image.jpg appear.
I try with different manners without result.
Some suggestions please ?
Your code suggests that the text "image.jpg" will fade in, not the
image itself. To do that, create a graded colour scale from #ffffff
to whatever the text colour should eventually be over the duration of
the fade in steps of say 20ms. On each step, set that as the value
for the div's style.color property. Ideally, you have now set it to
the original value of the div's style.color property and so can end
with '' (empty string).

How you do that will range in complexity depending on your
requirements - perhaps you want to read the color value for the div,
maybe you want to set it in the call or perhaps you just want to
assume black.

Over to you.
--
Rob
Aug 5 '08 #3
On 5 Ago, 03:42, RobG <rg...@iinet.net.auwrote:
On Aug 5, 9:13*am, pt36 <key.albe...@gmail.comwrote:


Hi
I have a small script
function photo(a){
var photo = a ;
document.getElementById(photoID).innerHTML = photo;
}
and on the body
... onclick="photo('image.jpg')"
I liked to have a fadeIn when the image.jpg appear.
I try with different manners without result.
Some suggestions please ?

Your code suggests that the text "image.jpg" will fade in, not the
image itself. *To do that, create a graded colour scale from #ffffff
to whatever the text colour should eventually be over the duration of
the fade in steps of say 20ms. *On each step, set that as the value
for the div's style.color property. *Ideally, you have now set it to
the original value of the div's style.color property and so can end
with '' (empty string).

How you do that will range in complexity depending on your
requirements - perhaps you want to read the color value for the div,
maybe you want to set it in the call or perhaps you just want to
assume black.

Over to you.

--
Rob- Nascondi testo citato

- Mostra testo citato -
Hi Rob
thanks for your answer and your time
Sorry.
You are right, I write not correct
my code is
onclick="photo('<img src=image.jpg>')"
Aug 5 '08 #4
On Aug 5, 12:46 pm, pt36 <key.albe...@gmail.comwrote:
[...]
Hi Rob
thanks for your answer and your time
Sorry.
You are right, I write not correct
my code is
onclick="photo('<img src=image.jpg>')"
Rather than setting the innerHTML, use DOM methods instead. It's poor
form to have a local variable that has the same name as the function
itself and variable names should be meaningful and reflect what they
do, so:

function showPhoto(imgSrc)
{
var el = document.getElementById('photoID');
var img = document.createElement('img');
img.src = imgSrc;

// Clear out child nodes
while (el.firstChild) {
el.removeChild(el.firstChild);
}

// Insert image
el.appendChild(img);

fade(image, true);

}

function fade(el, direction) {

/* Set the image's opacity to zero or 1 based on
** direction (true == in, otherwise out) then fade
** it using setTimeout to keep calling fade until
** it's fully visible (or not). Look in the archives
** for an opacity setting function - good ones are
** quite a bit of code.
*/

}
--
Rob
Aug 5 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jase_dukerider | last post by:
Hi I have an assignment to hand in shortly for which I am after some guidance. The task is to read a WAV file, request a fade in /out time for the track from the user and the do the fade by...
4
by: Chris Lieb | last post by:
Hi, I am writing a class in JavaScript to cause a repeating fade effect. The fade class takes care of the fading and the rgb class takes care of manipulating rgb values: function rgb(red,...
2
by: Emil | last post by:
Hi, if you open the link below and click on "Show Me" and then "Toggle Transition" Button you will see a wonderfull fade in / fade out transition of 2 pictures. ...
1
by: Theseus | last post by:
Hello to all, I've got an issue where i don't know what solution i can implement. I'm not sure what script best can be used. I've got samples .jpg images to better describe my problem. Stage...
6
by: Jake Barnes | last post by:
Please go look at this page using FireFox: http://www.ralphkrubner.com/Commercial/ Click the "Next" button a few times. The images fade out and then fade in. It's a nice effect. Now do try...
0
by: tristanlbailey | last post by:
I have been attempting to solve this problem for a few weeks now, but I'm not having much luck... I would like to create a seamless fading effect on each form/window in my program; one that, when...
2
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, I made a usercontrol and want to give fade effects to it. Now problem is that i m using alpha command as i use in my cool form. Nothing is happninig. How can i give fade effect to a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.