javascript - having issue to calculate each div top and left position in masonry grid -


I have created a grid gallery where each division has different width and height I want to make this gallery like masonry < / P>

This is my

JavaScript snippet of code here

  function posit () {$ (". Sli"). CSS ({"status": "relative"}); Var k = 0; Total = $ (". Sli1"). Length; $ (This) .css ({"position"} ($ ("sli1") each (function () {// alert (k ++); // var selectpos = selectedItems.position (): "absolute"}) ; Var c = $ (this) .position (); console.log ((k) + ':' + c.left); var d = $ (this) .autterwidth (); $ (this) .css ({ "Left": (c.left)}; $ (this). Css ({"top": (c.top)}}}}} k ++;}; $ (document) .ready (function ) {posit ();});   

Can anyone help in calculating the same top and left position in each division so that I can mason? Please note : - I do not want to use any plugins Thankx in advance.

UPDATED Here is the screenshot. How do I get my output Enter image details here < / Div>

You can use this code. I used the method to get the top, right, bottom, left value

I modified your code a bit, please check that it works for you.

  $ (". Sli1"). Each (function () {var i = $ (this); i.css ({"position": "full"}) var c = i.get (0) .getBoundingClientRect (); console.log (c.top , c.left, c.bottom, c.right);});    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -