Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Masonry use as RTL (Right-To-Left) direction

Masonry worked fine with the text direction from LTR (Left-To-Right). Now I want to use masonry with the text direction RTL (Right-To-Left [Middle eastern languages such as Hebrew and Arabic are written predominantly right-to-left.] ).

Whenever I run masonry on the RTL (Right-To-Left) text direction, the masonry plugin setups all its grid layout in the LTR (Left-To-Right) format.

I also go through from the masonry plugin's documentation but didn't find any setting related to RTL (Right-To-Left) direction.

Any proposed solution?

like image 398
Dawood Butt Avatar asked Feb 11 '14 12:02

Dawood Butt


People also ask

What is the masonry layout system?

Masonry layout is a layout method where one axis uses a typical strict grid layout, most often columns, and the other a masonry layout. On the masonry axis, rather than sticking to a strict grid with gaps being left after shorter items, the items in the following row rise up to completely fill the gaps.

What is LTR and RTL?

The main difference between left-to-right (LTR) and right-to-left (RTL) language scripts is the direction in which content is displayed: LTR languages display content from left to right. RTL languages display content from right to left.


4 Answers

I think isOriginLeft: false is the right answer, according to this site

like image 57
Moe Far Avatar answered Sep 23 '22 01:09

Moe Far


If you want right-to-left layout, especially when your content includes images; Like Bootstrap cards that may contain images. Then get help from this code snippet.

Note: You need two libraries, Masonry and imagesLoaded:

<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
<script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.min.js"></script>
//See docs: https://masonry.desandro.com/layout.html#imagesloaded
//See demo: https://codepen.io/desandro/pen/MwJoLQ
var grid = document.querySelector('.masonry');
var msnry;

imagesLoaded(grid, function () {
    // init Isotope after all images have loaded
    msnry = new Masonry(grid, {
        // options
        percentPosition: true,
        originLeft: false
    });
});

Also, Considering the removal of Masonry from Bootstrap 5, the above may be a good guide for those friends.

like image 28
Alireza Rezaee Avatar answered Sep 23 '22 01:09

Alireza Rezaee


OriginLeft

Controls the horizontal flow of the layout. By default, item elements start positioning at the left, with originLeft: true. Set originLeft: false for right-to-left layouts.

originLeft: false
like image 42
Amr Ibrahim Avatar answered Sep 23 '22 01:09

Amr Ibrahim


You can float the items right in css:

.masonry .item {
  float: right;
}

then change the option isOriginLeft: false in your javascript.

Here is a little codepen to illustrate:

http://codepen.io/anon/pen/gkCiG

like image 41
Jeffrey Jenkinson Avatar answered Sep 21 '22 01:09

Jeffrey Jenkinson