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 < / 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
Post a Comment