PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Sun May 20, 2018 7:04 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Apr 07, 2012 7:51 pm 
Forum Contributor

Joined: Fri Dec 31, 2010 6:11 pm
Posts: 134
Hello, I am trying to use the iterator from a for loop as a variable that would dictate various css attributes on a page. So here is the loop. It is actually part of a larger program which I won't and has been greatly edited because what the program tries to accomplish is irrelevant to my question. It works except that I'm not sure how to set that iterator as attribute values.

Syntax: [ Download ] [ Hide ]

                                for(i = 0; i < frame_count; i++){

                                                                                                        $(".frame").slice(i,i+1).show(); //Display right odd frames

                                                                        $(".frame").slice(i,i+1).css({"top":"-798px","left":"102px","z-index":"-1", "height":"380px", "width":"180px"});  //Position right odd frames

                                }//End of for loop

Now for this line, .slice(i,i+1).css({"top":"-798px","left":"102px","z-index":"-1", "height":"380px", "width":"180px"}); Im actually trying to replace the numeric values with multiples of i such as "top": "-798*i" or in some cases, a complex algebraic expression involving i such as "left":"(102*i + 3)px" How do I accomplish that? Any ideas please?

PostPosted: Fri Apr 20, 2012 5:43 pm 
Forum Contributor
User avatar

Joined: Tue Jun 17, 2008 1:41 pm
Posts: 113
If I understand what you are looking to do, you might want to create new parameters from the calculations inside the loop like this:
var multiple = -798*i;
var otherCalc = 102*i + 3;
Then refer to your new variables later instead of trying to put a calculation where a value should be.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group