Friday, 15 April 2011

alignment - Trying to use jQuery to horizontally distribute elements of different sizes in a -


I am trying to use jQuery to isolate these elements from space. As you can see, I am increasing the width of the object and want to reduce the width of the surrounding DIV to find an empty space. Then I divide that space and pull out each element from that amount (by right margin). Here's JSFild:

My question is: (Note: I'm using this as an opportunity to learn because I know there are other ways to do this) by decreasing 4 in the following line 4? I thought that math should do. Flower will be enough below it, but still there are about 4 pixels which break it down line if you take the -4 from the following line, then it breaks and I do not know why.

var spacer = (Math Floor (remaining / 4) -4);

Here's HTML:

  & lt; Div & gt; & Lt; Period & gt; Small & lt; / Span & gt; & Lt; Span & gt; A very long forest is right & lt; / Span & gt; & Lt; Period & gt; Small & lt; / Span & gt; & Lt; Period & gt; Small & lt; / Span & gt; & Lt; Period & gt; Small & lt; / Span & gt; & Lt; / Div & gt;   

And here's jQuery:

  var measurement = 0; . {Measurement + = $ ('time') eq (i) .width (); for & lt; = 4; i = ii ++); } Var totalWidth = $ ('div'). Width (); Var balance = 0; Balance = totalWidth - measurement; Var spacer = (Math Floor (remaining / 4) -4); {$ ('Time') eq (i) .css ('margin-right', spacer). (; I & lt; = 3 i ++ for I = 0); }            

Pre> & lt; Div & gt; & Lt; Period & gt; Small & lt; / Span & gt; & Lt; Period & gt; For a very long time, one right here & lt; / Span & gt; & Lt; Period & gt; Small & lt; / Span & gt; & Lt; Period & gt; Small & lt; / Span & gt; & Lt; Period & gt; Small & lt; / Span & gt; & Lt; / Div & gt;



No comments:

Post a Comment