4 Replies - 1378 Views - Last Post: 11 April 2012 - 06:52 PM

#1 drayarms   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 199
  • Joined: 18-May 11

How can one set a jQ variable as an attribute?

Posted 07 April 2012 - 05:51 PM

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.


				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?

Is This A Good Question/Topic? 0
  • +

Replies To: How can one set a jQ variable as an attribute?

#2 X-spert   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 56
  • Joined: 25-August 11

Re: How can one set a jQ variable as an attribute?

Posted 09 April 2012 - 08:16 AM

Hi,

You can try to put the expressions in local variables. Just a thought...

Good Luck!
Was This Post Helpful? 0
  • +
  • -

#3 e_i_pi   User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

Re: How can one set a jQ variable as an attribute?

Posted 11 April 2012 - 07:43 AM

View Postdrayarms, on 08 April 2012 - 11:51 AM, said:

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?

Try this:
...
  "top": (-798*i) + "px",
  "left": (102*i + 3) + "px",
...


Was This Post Helpful? 1
  • +
  • -

#4 X-spert   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 56
  • Joined: 25-August 11

Re: How can one set a jQ variable as an attribute?

Posted 11 April 2012 - 08:13 AM

View Poste_i_pi, on 11 April 2012 - 07:43 AM, said:

View Postdrayarms, on 08 April 2012 - 11:51 AM, said:

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?

Try this:
...
  "top": (-798*i) + "px",
  "left": (102*i + 3) + "px",
...



Yes, now I understood the real question...

Quote

e_i_pi
's answer is right...
Was This Post Helpful? 0
  • +
  • -

#5 drayarms   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 199
  • Joined: 18-May 11

Re: How can one set a jQ variable as an attribute?

Posted 11 April 2012 - 06:52 PM

@ expert, that's a right way to do it. i had figured it out. thanks though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1