/    Sign up×
Community /Pin to ProfileBookmark

Fade-in or slide-in function onload

I am trying to find a way to either fade-in or slide-in colored squares on a site. I want it to start onload fade-in the upper left hand square and go around the page doing the same thing, one after another.

webpage: [url]www.edrafting.homeip.net[/url]

Can anyone point me in the right direction?

Thanks,

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@rnd_meDec 16.2008 — add this to a script tag in your page:


[CODE]
window.onload=function(){
//stock code
function el(tid){if(tid.nodeName){return tid;}return el._ts[tid]||(el._ts[tid]=document.getElementById(tid));};el._ts={};
function trans(elm, opacity) { el(elm).style.opacity = (opacity / 100);}
function transIE(elm, opacity) { el(elm).style.filter = "alpha(opacity=" + opacity + ")";}
if(window.ActiveXObject){ trans= transIE; }



//customize from here below :

//a list of the ids of the tags you want to reveal.
var elms=["box1", "box2", "box3","box4","box5",
"box6","box7","box8","box9","box10",
"box11","box12", "box13", "box14", "box15"];



for(var i=0;i<elms.length;i++){ trans(elms[i],0) }; //first hide them all

for(var i=0;i<elms.length;i++){ //schedule them to unhide on a timeout...
setTimeout("trans('"+elms[i]+"', 100);document.title='"+elms[i]+"'", i * 500);
} //change 500 to the # of ms between each reveal

}
[/CODE]
Copy linkTweet thisAlerts:
@jaiantbassauthorDec 16.2008 — when I put this in the head of the page, it gives me an error of trans not defined:

<i>
</i>setTimeout("trans('"+elms[i]+"', 100);document.title='"+elms[i]+"'", i * 500);


Then if I want the elements to be hidden when the page loads, I can just hide them with a css rule and then fade them in?

Thanks so much for your help.
Copy linkTweet thisAlerts:
@infinityspiralDec 16.2008 — This is very easy to do if you have the jQuery library installed. You'd just created a variable to keep track of the square number and then you could use the fadein animation(http://docs.jquery.com/Effects/fadeIn) You can use the callback function part of the fadein animation to increment the variable that targets the correct square
Copy linkTweet thisAlerts:
@rnd_meDec 16.2008 — 
Then if I want the elements to be hidden when the page loads, I can just hide them with a css rule and then fade them in?

[/QUOTE]


if you do it with css instead of first-thing with javascript, no-one without javascript enabled will be able to view your page. thats why i hid with JS.


you need to copy all the functions in the code i posted. sounds like you might be missing one...
Copy linkTweet thisAlerts:
@jaiantbassauthorDec 17.2008 — Here is what I have so far:

<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;

<i> </i>&lt;meta http-equiv="content-type" content="text/html; charset=utf-8"&gt;
&lt;title&gt;E Drafting - Home Page&lt;/title&gt;
&lt;link rel="stylesheet" type="text/css" href="plain.css" /&gt;
&lt;script type="text/javascript" src="sw.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
window.onload=function(){
//stock code
function el(tid){if(tid.nodeName){return tid;}return el._ts[tid]||(el._ts[tid]=document.getElementById(tid));};el._ts={};
function trans(elm, opacity) { el(elm).style.opacity = (opacity / 100);}
function transIE(elm, opacity) { el(elm).style.filter = "alpha(opacity=" + opacity + ")";}
if(window.ActiveXObject){ trans= transIE; }



//customize from here below :

//a list of the ids of the tags you want to reveal.
var elms=["box1", "box2", "box3","box4","box5",
"box6","box7","box8","box9","box10",
"box11","box12", "box13", "box14", "box15"];



for(var i=0;i&lt;elms.length;i++){ trans(elms[i],0) }; //first hide them all

for(var i=0;i&lt;elms.length;i++){ //schedule them to unhide on a timeout...
setTimeout("trans('"+elms[i]+"', 100);document.title='"+elms[i]+"'", i * 500);
} //change 500 to the # of ms between each reveal

}
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
/*Toggle Sound Script © John Davenport Scheuer
as first seen in www.dynamicdrive.com/forums (user name:
jscheuer1). Visit http://www.dynamicdrive.com for 100's
of DHTML scripts. This credit must remain for legal use.
*/
var sndEl="homepage/mixdown.mp3" //Set to name and path of your sound file

function toggleSound(){
if (document.all&amp;&amp;document.all.sound&amp;&amp;document.all.sound.src!=='')
document.all.sound.src=''
else if (document.getElementById&amp;&amp;document.getElementById('snd')){
sndEl=document.getElementById('snd')
document.getElementById('sndC').removeChild(sndEl)
}
else if (document.all&amp;&amp;document.all.sound&amp;&amp;document.all.sound.src=='')
document.all.sound.src=sndEl
else if (document.getElementById)
document.getElementById('sndC').appendChild(sndEl)
}
&lt;/script&gt;


&lt;/head&gt;
&lt;body&gt;

<i> </i> &lt;div id="maincontent"&gt;
<i> </i> &lt;div id="toprow"&gt;
<i> </i> &lt;div id="box1"&gt;&lt;/div&gt;

<i> </i> &lt;div id="box2"&gt; &lt;script type="text/javascript"&gt;
<i> </i> if (document.getElementById&amp;&amp;!document.getElementById('sound')){
<i> </i> document.write('&lt;div id="sndC" style="position:absolute;top:-1000px:left:-1000px;visibility:hidden;"&gt;')
<i> </i> document.write('&lt;embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" Name="MediaPlayer" id="snd" src="'+sndEl+'" AutoStart="true" ShowStatusBar="0" ShowControls="0" ShowDisplay="0" volume="1" HEIGHT="1" WIDTH="1" loop="true"&gt;')
<i> </i> document.write('&lt;/div&gt;')
<i> </i> }
<i> </i> document.write('&lt;input type="image" class="centerd" src="homepage/music.gif" onclick="toggleSound();"&gt;')
<i> </i> &lt;/script&gt;&lt;/div&gt;
<i> </i> &lt;div id="box3"&gt;&lt;/div&gt;
<i> </i> &lt;div id="box4"&gt;&lt;/div&gt;
<i> </i> &lt;div id="box5"&gt;&lt;a href="#"&gt;&lt;img class="centerd1" src="HomePage/Blk-Design.gif" width="70" height="40" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div id="kitchen"&gt;&lt;img src="HomePage/kitchen.gif" width="200" height="98" /&gt;&lt;/div&gt;
<i> </i> &lt;div id="box6"&gt;&lt;/div&gt;&lt;div id="box7"&gt;&lt;a href="#"&gt;&lt;img id="center7" src="HomePage/Blk-Design-Services.gif" width="56" height="39" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div id="box8"&gt;&lt;/div&gt;
<i> </i> &lt;div id="box9"&gt;&lt;a href="#"&gt;&lt;img class="centerd" src="HomePage/Blk-Contact-Us.gif" width="61" height="15" alt="Picture of a new kitchen" /&gt;&lt;/a&gt;&lt;/div&gt;
<i> </i> &lt;div id="box10"&gt;&lt;img src="HomePage/Montra.gif" width="160" height="71" alt="Designs with you in mind" /&gt;&lt;/div&gt;
<i> </i> &lt;div id="box11"&gt;&lt;/div&gt;
<i> </i> &lt;div id="box12"&gt;&lt;a href="#"&gt;&lt;img class="centerd1" src="HomePage/Blk-About-E.gif" width="68" height="39" alt="Picture of a new kitchen" /&gt;&lt;/a&gt;&lt;/div&gt;
<i> </i> &lt;div id="box13"&gt;&lt;/div&gt;
<i> </i> &lt;div id="box14"&gt;&lt;/div&gt;
<i> </i> &lt;div id="box15"&gt;&lt;/div&gt;&lt;div id="Neighborhood"&gt;&lt;img src="HomePage/Neighborhood.gif" width="196" height="196" alt="The Neighborhood" /&gt;&lt;/div&gt;
<i> </i> &lt;div id="logo"&gt;&lt;img class="centerd1" src="HomePage/logo.gif" width="622" height="172" alt="E Drafting Logo" /&gt;&lt;/div&gt;

<i> </i> &lt;/div&gt;

<i> </i> &lt;div id="rotate"&gt;
<i> </i> &lt;script type="text/javascript"&gt;
<i> </i> //Notes on Parameters: The only required parameter is the slides_array_name. If Width is used, so must Height.
<i> </i> //Interval is optional too. It is always last, either fourth after Width and Height or second after Slides_array_name.
<i> </i> //Usage: new inter_slide(Slides_array_name, Width, Height, Interval)
<i> </i> new inter_slide(slides)
<i> </i> &lt;/script&gt;
<i> </i> &lt;/div&gt;




<i> </i> &lt;/div&gt;
<i> </i>&lt;/body&gt;
&lt;/html&gt;




It still gives me trans is undefined when I run the page on line 31:

<i>
</i>setTimeout("trans('"+elms[i]+"', 100);document.title='"+elms[i]+"'", i * 500);


Sorry if I am missing something. Thanks again,
Copy linkTweet thisAlerts:
@jaiantbassauthorDec 17.2008 — infinityspiral -


This is very easy to do if you have the jQuery library installed. You'd just created a variable to keep track of the square number and then you could use the fadein animation(http://docs.jquery.com/Effects/fadeIn) You can use the callback function part of the fadein animation to increment the variable that targets the correct square
[/quote]


I haven't used jquery yet and the website isn't real clear to me on how to set this up with onload. Any advice on how to start or even where to start?

Thanks,
Copy linkTweet thisAlerts:
@jaiantbassauthorDec 17.2008 — So after fumbling around with jquery for a bit, I added the jquery library to the head and then added this inside a script tag:

<i>
</i> $(document).ready(function(){$("div.box1").fadeIn(6000);});


nothing is happening however. Am I on the right track?
Copy linkTweet thisAlerts:
@rnd_meDec 17.2008 — 

It still gives me trans is undefined when I run the page on line 31:
[/QUOTE]


sorry about that. i forgot that i had wrapped the onload around it.

this happened inbetween my last test and posting the code. bad idea.

anyways,

change
[CODE]if(window.ActiveXObject){ trans= transIE; }[/CODE]


to
[CODE]if(window.ActiveXObject){ trans= transIE; }
window.trans = trans;
window.el=el;[/CODE]


and everything will work as well as it did for me last night.

you shouldn't need several KB of extra code to do something simple like fade a few boxes...

if you are going to be adding a lot of things like this in the future, i would keep jQuery and dump my code and the dynamicDeprive script...

tested in ff3
Copy linkTweet thisAlerts:
@vwphillipsDec 17.2008 — [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/
.tst {
width:50px;height:50px;background-Color:red;float:left;
}

/*]]>*/
</style>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
// Basic Element Animator (11-October-2008) DRAFT
// by Vic Phillips http://www.vicsjavascripts.org.uk

// To progressively change the Left, Top, Width, Height or Opacity of an element over a specified period of time.

// **** Application Notes

// **** The HTML Code
//
// when moving an element the inline or class rule style position of the element should be assigned as
// 'position:relative;' or 'position:absolute;'
//
// The element would normally be assigned a unique ID name.
//

// **** Executing the Effect(Script)
//
// The effect is executed by an event call to function 'zxcBAnimator('left','tst1',20,260,2000);'
// where:
// parameter 0 = the mode(see Note 1). (string)
// parameter 1 = the unique ID name or element object. (string or element object)
// parameter 2 = the start position of the effect. (digits, for opacity minimum 0, maximum 100)
// parameter 3 = the finish position of the effect. (digits, for opacity minimum 0, maximum 100)
// parameter 4 = (optional) period of time between the start and finish of the effect in milliseconds. (digits or defaults to 2000 milliSeconds)
//
// Note 1: The default units(excepting opacity) are 'px'.
// Note 2: Examples modes: 'left', 'top', 'width', 'height', 'opacity.
// For hyphenated modes, the first character after the hyphen must be upper case, all others lower case.
// Note 3: To 'toggle' the effect include '#' in parameter 0.
// The first call will set the toggle parameters.
// Subsequent calls with '#' in parameter 0 and the same start and finish parameters will 'toggle' the effect.
// Note 4: The function may be re-executed with a different set of parameters (start/finish time or period)
// whenever required, say from an onclick/mouseover/out event.
// The period parameter will be retained unless re-specified.
//
// **** Advanced Applications
//
// It may be required to access the current value of the effect.
// The element effect is accessible from the element property
// element effect = elementobject[mode.replace(/[-#]/g,'')+'oop'];
// where mode is parameter 0 of the initial call.
// An array storing the current, start and finish values of the element effect may be accessed
// from the element effect.data as fields 0, 1 and 2 respectively
//

// **** General
//
// All variable, function etc. names are prefixed with 'zxc' to minimise conflicts with other JavaScripts.
// These characters may be changed to characters of choice using global find and replace.
//
// The Functional Code(about 2K) is best as an External JavaScript.
//
// Tested with IE7 and Mozilla FireFox on a PC.
//



// **** Functional Code - NO NEED to Change


function zxcBAnimator(zxcmde,zxcobj,zxcsrt,zxcfin,zxctime){
if (typeof(zxcobj)=='string'){ zxcobj=document.getElementById(zxcobj); }
if (!zxcobj||(!zxcsrt&&!zxcfin)||zxcsrt==zxcfin) return;
var zxcoop=zxcobj[zxcmde.replace(/[-#]/g,'')+'oop'];
if (zxcoop){
clearTimeout(zxcoop.to);
if (zxcoop.srtfin[0]==zxcsrt&&zxcoop.srtfin[1]==zxcfin&&zxcmde.match('#')) zxcoop.update([zxcoop.data[0],(zxcoop.srtfin[0]==zxcoop.data[2])?zxcfin:zxcsrt],zxctime);
else zxcoop.update([zxcsrt,zxcfin],zxctime);
}
else zxcobj[zxcmde.replace(/[-#]/g,'')+'oop']=new zxcBAnimatorOOP(zxcmde,zxcobj,zxcsrt,zxcfin,zxctime);
}

function zxcBAnimatorOOP(zxcmde,zxcobj,zxcsrt,zxcfin,zxctime){
this.srtfin=[zxcsrt,zxcfin];
this.to=null;
this.obj=zxcobj;
this.mde=zxcmde.replace(/[-#]/g,'');
this.update([zxcsrt,zxcfin],zxctime);
}

zxcBAnimatorOOP.prototype.update=function(zxcsrtfin,zxctime){
this.time=zxctime||this.time||2000;
this.data=[zxcsrtfin[0],zxcsrtfin[0],zxcsrtfin[1]];
this.srttime=new Date().getTime();
this.cng();
}

zxcBAnimatorOOP.prototype.cng=function(){
var zxcms=new Date().getTime()-this.srttime;
this.data[0]=(this.data[2]-this.data[1])/this.time*zxcms+this.data[1];
if (this.mde!='left'&&this.mde!='top'&&this.data[0]<0) this.data[0]=0;
if (this.mde!='opacity') this.obj.style[this.mde]=this.data[0]+'px';
else zxcOpacity(this.obj,this.data[0]);
if (zxcms<this.time) this.to=setTimeout(function(zxcoop){return function(){zxcoop.cng();}}(this),10);
else {
this.data[0]=this.data[2];
if (this.mde!='opacity') this.obj.style[this.mde]=this.data[0]+'px';
else zxcOpacity(this.obj,this.data[0]);
}
}

function zxcOpacity(zxcobj,zxcopc){
if (zxcopc<0||zxcopc>100) return;
zxcobj.style.filter='alpha(opacity='+zxcopc+')';
zxcobj.style.opacity=zxcobj.style.MozOpacity=zxcobj.style.KhtmlOpacity=zxcopc/100-.001;
}

/*]]>*/
</script>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
var elms=["box1", "box2", "box3","box4","box5",
"box6","box7","box8","box9","box10",
"box11","box12", "box13", "box14", "box15"];
var cnt=0;
function Test(){
zxcBAnimator('opacity',elms[cnt],0,100,2000);
cnt++;
if (cnt<elms.length) setTimeout(function(){Test(); },2000);

}

/*]]>*/
</script></head>

<body onload="Test();">
<div id="box1" class="tst"></div>
<div id="box2" class="tst"></div>
<div id="box3" class="tst"></div>
<div id="box4" class="tst"></div>
<div id="box5" class="tst"></div>
<div id="box6" class="tst"></div>
<div id="box7" class="tst"></div>
<div id="box8" class="tst"></div>
<div id="box9" class="tst"></div>
<div id="box10" class="tst"></div>
<div id="box11" class="tst"></div>
<div id="box12" class="tst"></div>
<div id="box13" class="tst"></div>
<div id="box14" class="tst"></div>
<div id="box15" class="tst"></div>

</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@jaiantbassauthorDec 17.2008 — These work great! I have it working now. Thanks so much for all your help.
×

Success!

Help @jaiantbass spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...