FOK!forum / Digital Corner / [Javascript] Foto faden van x naar y
hbruynwoensdag 3 mei 2006 @ 12:22
Hallo,

Ik ben op zoek naar een scriptje wat heel eenvoudig een fade doet van foto x naar foto y


x en y wil ik zelf opgeven bij het aanroepen van de functie.

tHenks
Darkomenwoensdag 3 mei 2006 @ 13:27
google is your friend
hbruynwoensdag 3 mei 2006 @ 13:39
yep, maar de scripts die ik vind zjin allemaal slideshows.
Ik zoek een functie waaraan ik x en y kan meegeven zodat plaatje x naar plaatje y wordt gefade.
Ruudwoensdag 3 mei 2006 @ 13:44
google is your friend

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!-- TWO STEPS TO INSTALL IMAGE FADER TRANSITION:

  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the last code into the BODY of your HTML document  -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->

<HEAD>

<style type="text/css">
#img1 {position:absolute; width:300px; height:100px; left:220px; top:525px; z-index:1; visibility:hidden;}
#img2 {position:absolute; width:300px; height:100px; left:220px; top:525px; z-index:2}
</style>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
/************************************************************************
Script made by Martial Boissonneault © 2001 http://getElementById.com/
This script may be used and changed freely as long as this msg is intact
Visit http://getElementById.com/ for more free scripts and tutorials.
*************************************************************************/
var ie5=(document.getElementById && document.all);
var ns6=(document.getElementById && !document.all);

nPlus = 5   //the % of fading for each step
speed = 50  //the speed

// You don't have to edit below this line
nOpac = 100
function FadeImg(){
    if(document.getElementById){
        document.getElementById('img1').style.visibility="visible";
        imgs = document.getElementById('img2');
   opacity = nOpac+nPlus;
   nOpac = opacity;
   setTimeout('FadeImg()',speed);
    if(opacity>100 || opacity<0){
        nPlus=-nPlus;
    }
    if(ie5){
        imgs.style.filter="alpha(opacity=0)";
   imgs.filters.alpha.opacity = opacity;
    }
    if(ns6){
        imgs.style.MozOpacity = 0 + '%';
   imgs.style.MozOpacity = opacity + '%';
    }
  }
}
onload=FadeImg;
//  End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->

<BODY>

<div id="img1">
  <img src="img/img1.gif" border=0 width=300 height=100>
</div>
<div id="img2">
  <img src="img/img2.gif" border=0 width=300 height=100>
</div>


<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size:  2.21 KB -->
hbruynwoensdag 7 juni 2006 @ 19:14
Ik ben idd een heel eind gekomen met dit script, maar...

Ik heb de site nu in frames opgebouwd. Het bovenste frame bevat bovenstaand script.
In het frame "menu" laat ik het bovenste frame opnieuw laden met als initiele foto een foto die ik ophaal uit de sessie. Deze foto is vanuit het menu in de sessie geplaatst.
Als fade-in foto geef ik een nieuwe foto mee via een variabele in de url.
Dit werkt, maar het opnieuw laden van het bovenste frame zorgt er voor dat het niet vloeiend overloopt.

Dit is de (html) code van het bovenste frame:
1
2
3
4
5
6
7
8
9
<body onload=FadeImg('img1','img2')>
<div style=background-color:#FFFFFF;height:10px;width:100%>
</div>
<div id="img1" width=100% align=center style="background-color:FFFFFF" >
  <img src="images/<?=$img1;?>.jpg">
</div>
<div id="img2" width=100% align=center style="background-color:FFFFFF" >
  <img src="images/<?=$img2;?>.jpg">
</div>


Wat ik nu nog wil is het bovenste frame niet opnieuw laden, maar een javascript functie die van plaatje x naar plaatje y fade, en ik wil bij het aanroepen plaatje y meegeven, plaatje x is het huidige plaatje.

Wie o wie helpt me uit de brand?
hbruyndonderdag 8 juni 2006 @ 08:45
kick
hbruyndonderdag 8 juni 2006 @ 15:47
Nog maar een keer
joehoeeee


kick
Darkomendonderdag 8 juni 2006 @ 16:17
Zo ongeduldig he, als iemand het antwoord voor je heeft dan krijg je dat wel te zien.
Maar heb je een online voorbeeld, je beschrijving zegt weinig.
hbruynvrijdag 9 juni 2006 @ 13:37
Ja, ja, maar het is een opdracht voor een klant, en ik wil er vanaf zijn.

Enfin.
Ik heb intussen een ander script gevonden, maar op een klein deel na werkt het.
De foto die gefade wordt heeft id "test" en staat in een frame met de naam "header".
De functie wordt als volgt aangeroepen:
1crossfade(parent.header.test, 'images/plaatje2.jpg', '1', '');

De fout die ik krijg op regel 141 in het script is: "Kan lid niet vinden"
Hieronder het gehele script.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// IXF1.11 :: Image cross-fade 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
//******************************************************
//global object
var ixf = { 'clock' : null, 'count' : 1 }
/*******************************************************


/*****************************************************************************
 List the images that need to be cached
*****************************************************************************/

ixf.imgs = [
   'images/home.jpg',
   'images/agenda.jpg',
   ];

/*****************************************************************************
*****************************************************************************/


//cache the images
ixf.imgsLen = ixf.imgs.length;
ixf.cache = [];
for(var i=0; i<ixf.imgsLen; i++)
{
   ixf.cache[i] = new Image;
   ixf.cache[i].src = ixf.imgs[i];
}


//crossfade setup function
function crossfade()
{
   //if the timer is not already going
   if(ixf.clock == null)
   {
      //copy the image object 
      ixf.obj = arguments[0];
      
      //copy the image src argument 
      ixf.src = arguments[1];
      
      //store the supported form of opacity
      if(typeof ixf.obj.style.opacity != 'undefined')
      {
         ixf.type = 'w3c';
      }
      else if(typeof ixf.obj.style.MozOpacity != 'undefined')
      {
         ixf.type = 'moz';
      }
      else if(typeof ixf.obj.style.KhtmlOpacity != 'undefined')
      {
         ixf.type = 'khtml';
      }
      else if(typeof ixf.obj.filters == 'object')
      {
         //weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
         //then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
         //then the returned value type, which should be a number, but in mac/ie5 is an empty string
         ixf.type = (ixf.obj.filters.length > 0 && typeof ixf.obj.filters.alpha == 'object' && typeof ixf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
      }
      else
      {
         ixf.type = 'none';
      }
      
      //change the image alt text if defined
      if(typeof arguments[3] != 'undefined' && arguments[3] != '')
      {
         ixf.obj.alt = arguments[3];
      }
      
      //if any kind of opacity is supported
      if(ixf.type != 'none')
      {
         //create a new image object and append it to body
         var doc = parent.header.document;

         ixf.newimg = doc.createElement('img');

         //set positioning classname
         ixf.newimg.className = 'idupe';
         
         //set src to new image src
         ixf.newimg.src = ixf.src

         //move it to superimpose original image
         ixf.newimg.style.left = ixf.getRealPosition(ixf.obj, 'x') + 'px';
         ixf.newimg.style.top = ixf.getRealPosition(ixf.obj, 'y') + 'px';
         
         //copy and convert fade duration argument 
         ixf.length = parseInt(arguments[2], 10) * 1000;
         
         //create fade resolution argument as 20 steps per transition
         ixf.resolution = parseInt(arguments[2], 10) * 20;
         
         //start the timer
         ixf.clock = setInterval('ixf.crossfade()', ixf.length/ixf.resolution);
      }
      
      //otherwise if opacity is not supported
      else
      {
         //just do the image swap
         ixf.obj.src = ixf.src;
      }
      
   }
};


//crossfade timer function
ixf.crossfade = function()
{
   //decrease the counter on a linear scale
   ixf.count -= (1 / ixf.resolution);
   
   //if the counter has reached the bottom
   if(ixf.count < (1 / ixf.resolution))
   {
      //clear the timer
      clearInterval(ixf.clock);
      ixf.clock = null;
      
      //reset the counter
      ixf.count = 1;
      
      //set the original image to the src of the new image
      ixf.obj.src = ixf.src;
   }
   
   //set new opacity value on both elements
   //using whatever method is supported
   switch(ixf.type)
   {
      case 'ie' :
         ixf.obj.filters.alpha.opacity = ixf.count * 100;
         ixf.newimg.filters.alpha.opacity = (1 - ixf.count) * 100;
         break;
         
      case 'khtml' :
         ixf.obj.style.KhtmlOpacity = ixf.count;
         ixf.newimg.style.KhtmlOpacity = (1 - ixf.count);
         break;
         
      case 'moz' : 
         //restrict max opacity to prevent a visual popping effect in firefox
         ixf.obj.style.MozOpacity = (ixf.count == 1 ? 0.9999999 : ixf.count);
         ixf.newimg.style.MozOpacity = (1 - ixf.count);
         break;
         
      default : 
         //restrict max opacity to prevent a visual popping effect in firefox
         ixf.obj.style.opacity = (ixf.count == 1 ? 0.9999999 : ixf.count);
         ixf.newimg.style.opacity = (1 - ixf.count);
   }
   
   //now that we've gone through one fade iteration 
   //we can show the image that's fading in
   ixf.newimg.style.visibility = 'visible';
   
   //keep new image in position with original image
   //in case text size changes mid transition or something
   ixf.newimg.style.left = ixf.getRealPosition(ixf.obj, 'x') + 'px';
   ixf.newimg.style.top = ixf.getRealPosition(ixf.obj, 'y') + 'px';
   
   //if the counter is at the top, which is just after the timer has finished
   if(ixf.count == 1)
   {
      //remove the duplicate image
      //ixf.newimg.parentNode.removeChild(ixf.newimg);
   }
};


//get real position method
ixf.getRealPosition = function()
{
   this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;
   this.tmp = arguments[0].offsetParent;
   while(this.tmp != null)
   {
      this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;
      this.tmp = this.tmp.offsetParent;
   }
   
   return this.pos;
};


Ik hoop dat je me hiermee kunt helpen

Bedankt alvast.
hbruynmaandag 12 juni 2006 @ 08:44
kick
fokME2maandag 12 juni 2006 @ 09:18
[Javascript] voor dummies - deel 4

Daar heb je meer kans op iemand met een antwoord op je vraag. Ik zal straks ook even kijken.
hbruyndonderdag 15 juni 2006 @ 22:59
Heb je al tijd gehad?

bedankt alvast
hbruyndinsdag 20 juni 2006 @ 13:49
kick
Scorpionsworlddinsdag 20 juni 2006 @ 16:00
quote:
Op vrijdag 9 juni 2006 13:37 schreef hbruyn het volgende:
Ja, ja, maar het is een opdracht voor een klant, en ik wil er vanaf zijn.

Enfin.
Ik heb intussen een ander script gevonden, maar op een klein deel na werkt het.
De foto die gefade wordt heeft id "test" en staat in een frame met de naam "header".
De functie wordt als volgt aangeroepen:
[ code verwijderd ]

De fout die ik krijg op regel 141 in het script is: "Kan lid niet vinden"
Hieronder het gehele script.
[ code verwijderd ]

Ik hoop dat je me hiermee kunt helpen

Bedankt alvast.
Heb je de css van de originele download gebruikt?
hbruynzaterdag 24 juni 2006 @ 08:53
Ja, die heb ik gebruikt...
Scorpionsworldmaandag 26 juni 2006 @ 10:54
quote:
Op zaterdag 24 juni 2006 08:53 schreef hbruyn het volgende:
Ja, die heb ik gebruikt...
Goed...
Na zelf een test frameset opgesteld te hebben ben ik wat gaan testen en kwam tot de volgende werkende conclusie:
1crossfade(parent.header.test, 'images/plaatje2.jpg', '1', '');

vervangen voor
1crossfade(parent.header.document.getElementById('test'), 'images/plaatje2.jpg', '1', '');
in je functieaanroep.