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?
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.
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.
I think isOriginLeft: false
is the right answer, according to this site
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With