PDA

View Full Version : Help..


pharma
11-01-2002, 06:50 AM
whats wrong with this script? i cant find it..





nereidFadeObjects = new Object();
nereidFadeTimers = new Object();

/* object - image to be faded (actual object, not name);
* destop - destination transparency level (ie 80, for mostly solid)
* rate - time in milliseconds between trasparency changes (best under 100)
* delta - amount of change each time (ie 5, for 5% change in transparency)
*/

function nereidFade(object, destOp, rate, delta){
if (!document.all)
return
if (object != "[object]"){ //do this so I can take a string too
setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
return;
}

clearTimeout(nereidFadeTimers[object.sourceIndex]);

diff = destOp-object.filters.alpha.opacity;
direction = 1;
if (object.filters.alpha.opacity > destOp){
direction = -1;
}
delta=Math.min(direction*diff,delta);
object.filters.alpha.opacity+=direction*delta;

if (object.filters.alpha.opacity != destOp){
nereidFadeObjects[object.sourceIndex]=object;
nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
}
}



function alvin_on(){
hover('alvin');
out('dan')}
function alvin_off(){
hover('alvin');
hover('dan')}

function dan_on(){
hover('dan');
out('alvin')}
function dan_off(){
hover('dan');
hover('alvin')}


function hover(name){
document.all[name].onmouseover='nereidFade(this,100,30,15)'}

function out(name){
document.all[name].onmouseover='nereidFade(this,30,30,15)'}



*under body*
<img id="alvin" src="creditors/alvin.jpg" onmouseover="alvin_on()" onmouseout="alvin_off()">
<img id="dan" src="creditors/dan.jpg" onmouseover="dan_on()" onmouseout="dan_off()">

mordred
11-01-2002, 02:19 PM
1. Use descriptive topic titles. Is it really so hard or are just lazy?

2. It's just a little to few information you give us. What is not working? What is the intended use of the script? Did you get any error messages? Did the monitor go dark? You heard your sysadmin screaming? Give us something to chew on.

Please read http://www.codingforums.com/postguide.htm immediately, thanks. :)

Anyway, I *suspect* your error is somewhere around here...


function hover(name){
document.all[name].onmouseover='nereidFade(this,100,30,15)'}

function out(name){
document.all[name].onmouseover='nereidFade(this,30,30,15)'}


That's not proper JS. You assign a function reference or a newly constructed function object or an anonymous function to an event handler this way. However, you might run into problems because you use 'this' to refer to the event starting element. So better make it

<img id="alvin" src="creditors/alvin.jpg" onmouseover="'nereidFade(this,30,30,15)'">

You get the idea. Only that I don't understand why you have this "object != '[object]'" in the function, perhaps you can explain it. Also, your mouseover handling functions look very convoluted to me.

beetle
11-01-2002, 02:29 PM
pharma, mordred...

The purpose for the condition (object != "[object]") is to test if object is actually an object. I suspect pharma came to this conclusion by alerting object and was shown '[object]' in the alert window. I suppose it is a logical assumption that the above condition would function correctly based on the results of the alert, but it is improper. To properly check a variable for type, we need the typeof keyword.if (typeof object != "object"){ //do this so I can take a string too

Since this function accepts objects or strings, we could just as effectively use:if (typeof object == "string") { //do this so I can take a string tooGot all that? :D

pharma
11-02-2002, 01:38 PM
oh ok. sorry for that.

anyway, i got this script for DDrive. i posted it in the DDrive Script Help but no one relpied my posts. so i tried it here.

its called the Gradual Highlight Script II. im trying to modify it for the effect that i really want. well, here hows what it want it to be.. once i mouseover on one image, the other image gradually hides itself. then onmouseout, the other image will gradually shows up again.



this is the part that i added with the script, hoping to get the effect that i want..

function alvin_on(){
hover('alvin');
out('dan')}
function alvin_off(){
hover('alvin');
hover('dan')}

function dan_on(){
hover('dan');
out('alvin')}
function dan_off(){
hover('dan');
hover('alvin')}


function hover(name){
document.all[name].onmouseover='nereidFade(this,100,30,15)'}

function out(name){
document.all[name].onmouseover='nereidFade(this,30,30,15)'}



i've also tried bettle's suggestion. but still, it wont work.

i cannot use this tag <img id="alvin" src="creditors/alvin.jpg" onmouseover="'nereidFade(this,30,30,15)'"> because this is the original tag of the script. so the effect will only apply to that image only. and thats not what i want.

WA
11-02-2002, 10:33 PM
pharma:
Please do not:

1) Post a Dynamic Drive related question outside the "Dynamic Drive" category.
2) Post the entire script. Rather, narrow the problem down first, then post only the part you're having trouble with

Please do:
Use a more descriptive title next time ("Help" is NOT descriptive)

Please understand that "officially", CodingForums.com does NOT support "Dynamic Drive" related questions. The DD category was simply added as a courtesy and legacy to Dynamic Drive in the old WA Forum. In fact, the category may be removed in the future. I understand you may not always get a response when you post your DD-related question in the Dynamic Drive category, but that's simply the way it is. The best way is still to contact the script's author directly for help.

mordred
11-03-2002, 10:39 AM
Originally posted by beetle
The purpose for the condition (object != "[object]") is to test if object is actually an object. I suspect pharma came to this conclusion by alerting object and was shown '[object]' in the alert window. I suppose it is a logical assumption that the above condition would function correctly based on the results of the alert, but it is improper. To properly check a variable for type, we need the typeof keyword.

Beetle, I know how to test for a variable's type. My question rather went to pharma to enlighten us why the code comment says "object - image to be faded (actual object, not name);" and then there is this crude kludge some lines later in the script. Looked to me as a fundamental logic problem, so I asked pharma to explain why it was written this way. Perhaps I should have better used "elaborate" than "explain". Anyway, since we now know pharma is not the original author, my question was directed to the wrong person.