I'm trying to write a script to animate the expanding of my div onclick.
I've managed to do this with simply doing it with simple recursive timeouts.
However, the page is dynamically generated basing on database results so the simplest way i thought of doing this was by making an object in js. All would be good except for inability to get a recursion working within the objects reach and with setTimeout();
Any help would be appreciated since im new to js and DOM.
The Div family.
<div id="outerPost"> <div id="postTitle" onclick="(new slider(this)).slide();"> <h2 class="title"><?php echo $row['title']; ?></h2> <h2 class="feed"><?php echo $row['name']; ?></h2> </div> <div id="content" style="display: none;"> <h2><?php echo formatDate($row['last_update']).$row['username']; ?></h2> <p><?php echo $row['content']; ?></p> </div> </div>
The Script itself.
function slider(element)
{
//Constants
this.SPEED = 5;
this.DISP_NONE = "none";
this.DISP_BLOCK = "block";
//Parameters
this.colapsable = element.parentNode.childNodes[3];
this.display = this.colapsable.style.display;
this.width = this.colapsable.style.width;
this.height = this.colapsable.style.height;
element.parentNode.childNodes[3].style.display = this.DISP_BLOCK;
this.chSize = this.colapsable.clientHeight;
this.cwSize = this.colapsable.clientWidth;
element.parentNode.childNodes[3].style.display = this.DISP_NONE;
this.i = 1;
this.j = 1;
this.wInterval = (this.cwSize-1)/20;
this.hInterval = (this.chSize-1)/20;
//Methods
this.slide = slide;
this.down = down;
this.up = up;
//Width manipulation was dropped.
}
function slide()
{
if(this.display == this.DISP_NONE)
{
this.colapsable.style.display = "block";
this.colapsable.style.height = this.i+"px";
this.down();
document.getElementById("test").innerHTML = "Element id = "+this.colapsable.parentNode.childNodes[1].childNodes[1].innerHTML+"</br>Display = "+this.display
+"<br/>PreferedWidth = "+this.cwSize+"<br/>PreferedHeight = "+this.chSize+"<br/>Width Interval = "
+this.wInterval+"<br/>Height Interval = "+this.hInterval+"<br/>Width = "+this.width
+"<br/>Height = "+this.colapsable.style.height;
}
else if(this.display == this.DISP_BLOCK)
{
document.getElementById("test").innerHTML = "Element id = "+this.colapsable.parentNode.childNodes[1].childNodes[1].innerHTML+"</br>Display = "+this.display
+"<br/>PreferedWidth = "+this.cwSize+"<br/>PreferedHeight = "+this.chSize+"<br/>Width Interval = "
+this.wInterval+"<br/>Height Interval = "+this.hInterval+"<br/>Width = "+this.width
+"<br/>Height = "+this.colapsable.style.height;
this.colapsable.style.display = "none";
}
}
//assumes that the height is already set to desired startign height.
function down()
{
this.colapsable.style.height = (this.i+=this.hInterval)+"px";
if(this.chSize > this.i+this.hInterval)
var t = setTimeout('this.down()',this.SPEED);
}
function up()
{
}
Heres the error description i was given by google chrome extension for js.
TypeError: Cannot read property 'style' of undefined [http://localhost/page/scripts/display.js:51]
Note that many parameters are there just for the troubleshooting purposes.
Any extra code you need from me for you to be able to help, ask.
Edited: I had forgotten that i was still trying to find a work around to setTimeout so had deleted it before i copied the code, ive added the bit in to whatever i thought should work but didnt.
Added an error description.
This post has been edited by Atspulgs: 04 July 2011 - 02:57 AM

New Topic/Question
Reply


MultiQuote



|