I am trying to take this slide-in onclick script and have the div slide-in onload without the option to have it slide-up onclick.
[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>
<script type=”text/javascript” src=”animate.js”></script>
<script type=”text/javascript”>
function slideExample1(elementId, headerElement)
{
var element = document.getElementById(elementId);
if(element.up == null || element.down)
{
animate(elementId, 0, 20, 150, 0, 250, null);
element.up = true;
element.down = false;
headerElement.innerHTML = ‘vvv’;
}
else
{
animate(elementId, 0, 20, 150, 130, 250, null);
element.down = true;
element.up = false;
headerElement.innerHTML = ‘^^^’;
}
}
</script>
</head>
<body>
<div style=”position:relative;
width:150px;
height:170px;
top:0px;
left:0px;”>
<div id=”exampleHeader1″
style=”position:absolute;
width:150px;
height:20px;
top:0px;
left:0px;
background:#3b587a;
text-align:center;
color:#FFFFFF;”
onclick=”slideExample1(‘examplePanel1’, this);”>
^^^
</div>
<div id=”examplePanel1″
style=”position:absolute;
width:150px;
height:130px;
top:20px;
left:0px;
background:#B1B579;
overflow:hidden;”>
Content1
</div>
</div>
</body>
</html>
Any ideas?
Thanks
[code=html]<body onload="slideExample1('examplePanel1', 'exampleHeader1');">[/code]
<i>
</i><body onload="slideExample1('examplePanel1', 'exampleHeader1');">
tivrfoa,
this is close,
<i>
</i><body onload="slideExample1('examplePanel1', 'exampleHeader1');">
Now the div is displayed when the pages loads then goes up. What I am trying to do is get the div to be hidden when the page loads, then slides into view. Any more ideas? Thanks so much for your help.[/QUOTE]
<body onload="slideExample1('examplePanel1', document.getElementById('exampleHeader1'));">
as astupidname said.<i>
</i>//This code was created by the fine folks at Switch On The Code - http://blog.paranoidferret.com
//This code can be used for any purpose
function animate(elementID, newLeft, newTop, newWidth,
newHeight, time, callback)
{
var el = document.getElementById(elementID);
if(el == null)
return;
var cLeft = parseInt(el.style.left);
var cTop = parseInt(el.style.top);
var cWidth = parseInt(el.style.width);
var cHeight = parseInt(el.style.height);
var totalFrames = 1;
if(time> 0)
totalFrames = time/40;
var fLeft = newLeft - cLeft;
if(fLeft != 0)
fLeft /= totalFrames;
var fTop = newTop - cTop;
if(fTop != 0)
fTop /= totalFrames;
var fWidth = newWidth - cWidth;
if(fWidth != 0)
fWidth /= totalFrames;
var fHeight = newHeight - cHeight;
if(fHeight != 0)
fHeight /= totalFrames;
doFrame(elementID, cLeft, newLeft, fLeft,
cTop, newTop, fTop, cWidth, newWidth, fWidth,
cHeight, newHeight, fHeight, callback);
}
function doFrame(eID, cLeft, nLeft, fLeft,
cTop, nTop, fTop, cWidth, nWidth, fWidth,
cHeight, nHeight, fHeight, callback)
{
var el = document.getElementById(eID);
if(el == null)
return;
cLeft = moveSingleVal(cLeft, nLeft, fLeft);
cTop = moveSingleVal(cTop, nTop, fTop);
cWidth = moveSingleVal(cWidth, nWidth, fWidth);
cHeight = moveSingleVal(cHeight, nHeight, fHeight);
el.style.left = Math.round(cLeft) + 'px';
el.style.top = Math.round(cTop) + 'px';
el.style.width = Math.round(cWidth) + 'px';
el.style.height = Math.round(cHeight) + 'px';
if(cLeft == nLeft && cTop == nTop && cHeight == nHeight
&& cWidth == nWidth)
{
if(callback != null)
callback();
return;
}
setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+','
+cTop+','+nTop+','+fTop+','+cWidth+','+nWidth+','+fWidth+','
+cHeight+','+nHeight+','+fHeight+','+callback+')', 40);
}
function moveSingleVal(currentVal, finalVal, frameAmt)
{
if(frameAmt == 0 || currentVal == finalVal)
return finalVal;
currentVal += frameAmt;
if((frameAmt> 0 && currentVal>= finalVal)
|| (frameAmt <0 && currentVal <= finalVal))
{
return finalVal;
}
return currentVal;
}
[code=html]
<script type="text/javascript">
function slideExample1(elementId, headerElement) {
var element = document.getElementById(elementId);
if(element.up == null || element.up) {
animate(elementId, 0, 20, 150, 130, 250, null);
element.down = true;
element.up = false;
headerElement.innerHTML = '^^^';
} else {
animate(elementId, 0, 20, 150, 0, 250, null);
element.up = true;
element.down = false;
headerElement.innerHTML = 'vvv';
}
}
</script>
[/code]
<i>
</i>//This code was created by the fine folks at Switch On The Code - http://blog.paranoidferret.com
//This code can be used for any purpose
function animate(elementID, newLeft, newTop, newWidth,
newHeight, time, callback)
{
var el = document.getElementById(elementID);
if(el == null)
return;
var cLeft = parseInt(el.style.left);
var cTop = parseInt(el.style.top);
var cWidth = parseInt(el.style.width);
var cHeight = parseInt(el.style.height);
var totalFrames = 1;
if(time> 0)
totalFrames = time/40;
var fLeft = newLeft - cLeft;
if(fLeft != 0)
fLeft /= totalFrames;
var fTop = newTop - cTop;
if(fTop != 0)
fTop /= totalFrames;
var fWidth = newWidth - cWidth;
if(fWidth != 0)
fWidth /= totalFrames;
var fHeight = newHeight - cHeight;
if(fHeight != 0)
fHeight /= totalFrames;
doFrame(elementID, cLeft, newLeft, fLeft,
cTop, newTop, fTop, cWidth, newWidth, fWidth,
cHeight, newHeight, fHeight, callback);
}
function doFrame(eID, cLeft, nLeft, fLeft,
cTop, nTop, fTop, cWidth, nWidth, fWidth,
cHeight, nHeight, fHeight, callback)
{
var el = document.getElementById(eID);
if(el == null)
return;
cLeft = moveSingleVal(cLeft, nLeft, fLeft);
cTop = moveSingleVal(cTop, nTop, fTop);
cWidth = moveSingleVal(cWidth, nWidth, fWidth);
cHeight = moveSingleVal(cHeight, nHeight, fHeight);
el.style.left = Math.round(cLeft) + 'px';
el.style.top = Math.round(cTop) + 'px';
el.style.width = Math.round(cWidth) + 'px';
el.style.height = Math.round(cHeight) + 'px';
if(cLeft == nLeft && cTop == nTop && cHeight == nHeight
&& cWidth == nWidth)
{
if(callback != null)
callback();
return;
}
setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+','
+cTop+','+nTop+','+fTop+','+cWidth+','+nWidth+','+fWidth+','
+cHeight+','+nHeight+','+fHeight+','+callback+')', 40);
}
function moveSingleVal(currentVal, finalVal, frameAmt)
{
if(frameAmt == 0 || currentVal == finalVal)
return finalVal;
currentVal += frameAmt;
if((frameAmt> 0 && currentVal>= finalVal)
|| (frameAmt <0 && currentVal <= finalVal))
{
return finalVal;
}
return currentVal;
}
<i>
</i><!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>
<script type="text/javascript" src="animate.js"></script>
<script type="text/javascript">
function slideExample1(elementId, headerElement)
{
var element = document.getElementById(elementId);
if(element.up == null || element.down)
{
animate(elementId, 0, 20, 150, 0, 250, null);
element.up = true;
element.down = false;
headerElement.innerHTML = 'vvv';
}
else
{
animate(elementId, 0, 20, 150, 130, 250, null);
element.down = true;
element.up = false;
headerElement.innerHTML = '^^^';
}
}
</script>
</head>
<body onload="slideExample1('examplePanel1', document.getElementById('exampleHeader1'));">
<div style="position:relative;
width:150px;
height:170px;
top:0px;
left:0px;">
<div id="exampleHeader1"
style="position:absolute;
width:150px;
height:20px;
top:0px;
left:0px;
background:#3b587a;
text-align:center;
color:#FFFFFF;"
<i> ></i>
</div>
<div id="examplePanel1"
style="position:absolute;
width:150px;
height:130px;
top:20px;
left:0px;
background:#B1B579;
overflow:hidden;
">
Content1
</div>
</div>
<div style="position:relative;
width:150px;
height:170px;
top:0px;
left:220px;">
<div id="exampleHeader2"
style="position:absolute;
width:150px;
height:20px;
top:0px;
left:0px;
background:#3b587a;
text-align:center;
color:#FFFFFF;"
onclick="slideExample1('examplePanel2', this);">
^^^
</div>
<div id="examplePanel2"
style="position:absolute;
width:150px;
height:130px;
top:20px;
left:0px;
background:#D1E5EF;
overflow:hidden;">
Content2
</div>
</div>
<div style="position:relative;
width:150px;
height:170px;
top:0px;
left:0px;">
<div id="exampleHeader3"
style="position:absolute;
width:150px;
height:20px;
top:0px;
left:0px;
background:#3b587a;
text-align:center;
color:#FFFFFF;"
onclick="slideExample1('examplePanel3', this);">
^^^
</div>
<div id="examplePanel3"
style="position:absolute;
width:150px;
height:130px;
top:20px;
left:0px;
background:#163188;
overflow:hidden;">
Content3
</div>
</div>
</body>
</html>
<i>
</i><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
.container div{width:100px; height:100px; position:absolute}
</style>
<script type="text/javascript">
i=-100;
var c;
function f(){
c=setInterval(function(){inv()},20)
}
function inv()
{
if(i!=0)
{
i+=5;
document.getElementsByTagName("div")[1].style.top=i+"px";
}
else
{
clearInterval(c);
document.getElementsByTagName("button")[0].parentNode.removeChild(document.getElementsByTagName("button")[0]);
}
}
</script>
</head>
<body onload="f()">
<div class="container" style="position:relative">
<div style="background:red; top:-100px; z-index:100">&nbsp;</div>
<div style="background:white; top:-100px; z-index:200">&nbsp;</div>
<div style="background:#ffffff; top:0px;">&nbsp;</div>
</div>
</body>
</html>
[CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<style type="text/css">
<!--
.slide {
position:absolute;left:-100;top:-100px;width:50px;height:50px;background-Color:red;
}
-->
</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 1.7K) is best as an External JavaScript.
//
// Tested with IE7 and Mozilla FireFox on a PC.
//
// **** Functional Code - NO NEED to Change
function zxcBAnimator(mde,obj,srt,fin,time){
if (typeof(obj)=='string'){ obj=document.getElementById(obj); }
if (!obj||(!srt&&!fin)||srt==fin) return;
var oop=obj[mde.replace(/[-#]/g,'')+'oop'];
if (oop){
clearTimeout(oop.to);
if (oop.srtfin[0]==srt&&oop.srtfin[1]==fin&&mde.match('#')) oop.update([oop.data[0],(oop.srtfin[0]==oop.data[2])?fin:srt],time);
else oop.update([srt,fin],time);
}
else obj[mde.replace(/[-#]/g,'')+'oop']=new zxcBAnimatorOOP(mde,obj,srt,fin,time);
}
function zxcBAnimatorOOP(mde,obj,srt,fin,time){
this.srtfin=[srt,fin];
this.to=null;
this.obj=obj;
this.mde=mde.replace(/[-#]/g,'');
this.update([srt,fin],time);
}
zxcBAnimatorOOP.prototype.update=function(srtfin,time){
this.time=time||this.time||2000;
this.data=[srtfin[0],srtfin[0],srtfin[1]];
this.srttime=new Date().getTime();
this.cng();
}
zxcBAnimatorOOP.prototype.cng=function(){
var ms=new Date().getTime()-this.srttime;
this.data[0]=(this.data[2]-this.data[1])/this.time*ms+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 (ms<this.time) this.to=setTimeout(function(oop){return function(){oop.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(obj,opc){
if (opc<0||opc>100) return;
obj.style.filter='alpha(opacity='+opc+')';
obj.style.opacity=obj.style.MozOpacity=obj.style.KhtmlOpacity=opc/100-.001;
}
/*]]>*/
</script>
<script language="JavaScript" type="text/javascript">
<!--
function zxcByClassName(zxcnme,zxcel,zxctag){
if (typeof(zxcel)=='string') zxcel=document.getElementById(zxcel);
zxcel=zxcel||document;
for (var zxctag=zxctag||'*',zxcreg=new RegExp('(^|\s)'+zxcnme+'(\s|$)'),zxcels=zxcel.getElementsByTagName(zxctag),zxcary=[],zxc0=0; zxc0<zxcels.length;zxc0++){
if(zxcreg.test(zxcels[zxc0].className)) zxcary.push(zxcels[zxc0]);
}
return zxcary;
}
function Load(cls){
var objs=zxcByClassName(cls);
for (var z0=0;z0<objs.length;z0++){
var split=objs[z0].className.split(':');
zxcBAnimator('left',objs[z0],split[1]-1,split[3]*1,split[5]);
zxcBAnimator('top',objs[z0],split[2]-1,split[4]*1,split[5]);
}
}
//-->
</script>
</head>
<body onload="Load('slide');" >
<div class="slide :-50:-50:450:50:1000" ></div>
<div class="slide :-50:250:450:100:2000" ></div>
</body>
</html>
[/CODE]
[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">
<!--
.slide {
position:relative;left:-100px;top:0px;width:50px;height:50px;background-Color:red;
}
-->
</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 1.7K) is best as an External JavaScript.
//
// Tested with IE7 and Mozilla FireFox on a PC.
//
// **** Functional Code - NO NEED to Change
function zxcBAnimator(mde,obj,srt,fin,time){
if (typeof(obj)=='string'){ obj=document.getElementById(obj); }
if (!obj||(!srt&&!fin)||srt==fin) return;
var oop=obj[mde.replace(/[-#]/g,'')+'oop'];
if (oop){
clearTimeout(oop.to);
if (oop.srtfin[0]==srt&&oop.srtfin[1]==fin&&mde.match('#')) oop.update([oop.data[0],(oop.srtfin[0]==oop.data[2])?fin:srt],time);
else oop.update([srt,fin],time);
}
else obj[mde.replace(/[-#]/g,'')+'oop']=new zxcBAnimatorOOP(mde,obj,srt,fin,time);
}
function zxcBAnimatorOOP(mde,obj,srt,fin,time){
this.srtfin=[srt,fin];
this.to=null;
this.obj=obj;
this.mde=mde.replace(/[-#]/g,'');
this.update([srt,fin],time);
}
zxcBAnimatorOOP.prototype.update=function(srtfin,time){
this.time=time||this.time||2000;
this.data=[srtfin[0],srtfin[0],srtfin[1]];
this.srttime=new Date().getTime();
this.cng();
}
zxcBAnimatorOOP.prototype.cng=function(){
var ms=new Date().getTime()-this.srttime;
this.data[0]=(this.data[2]-this.data[1])/this.time*ms+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 (ms<this.time) this.to=setTimeout(function(oop){return function(){oop.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(obj,opc){
if (opc<0||opc>100) return;
obj.style.filter='alpha(opacity='+opc+')';
obj.style.opacity=obj.style.MozOpacity=obj.style.KhtmlOpacity=opc/100-.001;
}
/*]]>*/
</script>
<script language="JavaScript" type="text/javascript">
<!--
function zxcByClassName(zxcnme,zxcel,zxctag){
if (typeof(zxcel)=='string') zxcel=document.getElementById(zxcel);
zxcel=zxcel||document;
for (var zxctag=zxctag||'*',zxcreg=new RegExp('(^|\s)'+zxcnme+'(\s|$)'),zxcels=zxcel.getElementsByTagName(zxctag),zxcary=[],zxc0=0; zxc0<zxcels.length;zxc0++){
if(zxcreg.test(zxcels[zxc0].className)) zxcary.push(zxcels[zxc0]);
}
return zxcary;
}
function Load(cls){
var objs=zxcByClassName(cls);
for (var z0=0;z0<objs.length;z0++){
var split=objs[z0].className.split(':');
zxcBAnimator('left',objs[z0],split[1]-1,split[3]*1,split[5]);
zxcBAnimator('top',objs[z0],split[2]-1,split[4]*1,split[5]);
}
}
//-->
</script>
</head>
<body onload="Load('slide');" >
<center>
<table border="1">
<tr>
<td width="50" >
<div style="position:relative;" >
<img class="slide :-600:-50:0:0:1000" src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" width="50" height="50" />
</div>
</td>
<td width="50" >
<div style="position:relative;" >
<img class="slide :-600:250:0:0:1000" src="http://www.vicsjavascripts.org.uk/StdImages/Two.gif" width="50" height="50" />
</div>
</td>
</tr>
</table>
</center></body>
</html>[/CODE]
0.1.9 — BETA 5.24