Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Passing variable as string into function
Old 12-18-2006, 10:36 AM Passing variable as string into function
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
I have a function called at load which runs through the page, truncates a dive down to the first paragraph, shrinks the div height and assigns an animation function to a button inside that div. So when someone clicks on the "more" button the script refills the div and then animates the opening of the div using mootools. I'm trying to pass the number that corresponds to the button, detail and fullText. (button 0 opens detail 0 and shows fullText 0), but when I say "x" in the assigned function I want that to be the literal value of whatever the loop is - if it's loop 0, write "0" into the function. Is there a way to do this, or should I find another way of storing the number? Thanks.

Code:
var buttons, details;
var fullText = [];
function setupDetails() {
	buttons = $S(".itemDetail .bottom"); //$S() returns an array of elements
	details = $S(".itemDetail .inside");
	for (x = 0; x<details.length; x++) {
		fullText[x] = details[x].innerHTML;
		details[x].addClass("shrunk");
		details[x].innerHTML = details[x].getElementsByTagName("p")[0].innerHTML.substring(0,200) + "...";
		details[x].style.height = details[x].offsetHeight + "px";
		buttons[x].onclick = function() {
			var myEffects = details[x].effects({duration: 500, transition: Fx.Transitions.sineInOut});
			myEffects.custom({'height': [details[x].offsetHeight, details[x].scrollHeight], onComplete : function() {
				details[x].innerHTML = fullText[x];
				details[x].removeClass("shrunk");
				}
			});
			this.parentNode.removeChild(this);
		}
	};
}
HTML Code:
<div class="itemDetail">
	<div class="inside">
		<p>Text</p>
	</div>
	<div class="bottom">Read More</div>
</div>

<div class="itemDetail">
	<div class="inside">
		<p>Text</p>
	</div>
	<div class="bottom">Read More</div>
</div>

Last edited by funkdaddu; 12-18-2006 at 10:38 AM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
 
Register now for full access!
Reply     « Reply to Passing variable as string into function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.69121 seconds with 12 queries