This package was originally a fork from https://github.com/jelgblad/angular2-masonry to allow it to work with newer versions of Angular.
This updated version is also compatible with Angular Universal server side rendering (SSR)
npm install ngx-masonry masonry-layout --save
Import NgxMasonryModule
into your app's modules:
import { NgxMasonryModule } from 'ngx-masonry';
@NgModule({
imports: [NgxMasonryModule]
})
@Component({
selector: 'my-component',
template: `
<ngx-masonry>
<div ngxMasonryItem class="masonry-item" *ngFor="let item of masonryItems">
{{item.title}}
</div>
</ngx-masonry>
`,
styles: [
`
.masonry-item { width: 200px; }
`
]
})
class MyComponent {
masonryItems = [
{ title: 'item 1' },
{ title: 'item 2' },
{ title: 'item 3' },
];
}
Append new items synchronously. The order of the items will be preserved, but one image in the middle will block the reset of the images.
<ngx-masonry [options]="masonryOptions" [ordered]="true">
Read about Masonry options here: Masonry Options
The options
-attribute takes an object with the following properties:
Inline object:
<ngx-masonry [options]="{ gutter: 10 }"></ngx-masonry>
From parent component:
import { NgxMasonryOptions } from 'ngx-masonry';
public myOptions: MasonryOptions = {
gutter: 10
};
<ngx-masonry [options]="myOptions"></ngx-masonry>
ngx-masonry has an input property, updateLayout
, which accepts a boolean and will call masonry's layout()
method on a change. It ignores the first change when the component loads.
<ngx-masonry [updateLayout]="updateMasonryLayout"></ngx-masonry>
When updateMasonryLayout
is updated, the layout()
method will be called.
You can create and set customized animations with this option.
animations = {
show: [
style({opacity: 0}),
animate('400ms ease-in', style({opacity: 1})),
],
hide: [
style({opacity: '*'}),
animate('400ms ease-in', style({opacity: 0})),
]
}
// To disable animation
animations = {}
Note that due to https://github.com/wynfred/ngx-masonry/issues/8 ngx-masonry comes without builtin animations of moving masonry items (when they change size or screen changes size). You can implement them using a css transition. Just add item css class let's say "masonry-item" and add this css code.
.masonry-item {
transition: top 0.4s ease-in-out, left 0.4s ease-in-out;
}
When using any lazyload methods layout, you can add masonryLazy
attribute to the images.
Note: When using masonryLazy
, the layout would have an overlapping issue. If you have this issue, you would need a custom method to maintain the layout, such as adding the fixed width/height to each image. For using the image lazyload method, you can have fallback image and loading indicator is recommended.
Example:
<img masonryLazy loading="lazy" width="500px" height="300px"/>
EventEmitter<any[]>
Triggered after a layout and all positioning transitions have completed.
EventEmitter<any[]>
Triggered after an item element has been removed.
EventEmitter<number>
Should only be used with ordered
mode. Triggered after the last item is loaded.
<ngx-masonry (layoutComplete)="doStuff($event)" (removeComplete)="doOtherStuff($event)"></ngx-masonry>
How to maintain the order of items if there are images?
Set [ordered]
to true.
To insert item at the beginning: prepend the item to the array and set prepend
to true.
<div ngxMasonryItem [prepend]="image.prepend" *ngFor="let image of masonryImages">
If item is inserted or the list is shuffled, use reloadItems()
// get reference
@ViewChild(NgxMasonryComponent) masonry: NgxMasonryComponent;
// after the order of items has changed
this.masonry.reloadItems();
this.masonry.layout();
Why is the transitionDuration option not supported?
The builtin animation of masonry-layout doesn't work with angular well.
For more information refer to this issue:
How to setup if I use SystemJS?
If you're using SystemJS add ngx-masonry
and masonry-layout
to your configuration:
packages: {
"ngx-masonry": { "defaultExtension": "js", "main": "index" }
},
map: {
"ngx-masonry": "node_modules/ngx-masonry",
"masonry-layout": "node_modules/masonry-layout/dist/masonry.pkgd.js"
}
Where is imagesLoaded?
imagesLoaded is removed in V9. masonry item will support image by default
This repository contains a working app using ngx-masonry as a child module, not as an npm package. You can go to the demo respository to view an app that uses it as an npm package.
报错: src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’: src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=] h ^= data[2] << 16;
ngx_stream_core_module 示例配置 指令 listen preread_buffer_size preread_timeout proxy_protocol_timeout resolver resolver_timeout server stream tcp_nodelay variables_hash_bucket_size variables_hash_max_size
ngx_http_memcached_module 指令 memcached_bind memcached_buffer_size memcached_connect_timeout memcached_force_ranges memcached_gzip_flag memcached_next_upstream memcached_next_upstream_timeout memcached
在计算机语言中,变量是用来存储和表示数据的,但不同的语言表示变量的方式不同,像java语言会把变量抽象成各种类型,并且每种类型都会用一个特殊的符号表示,比如表示一个整数需要这样: int age= 25; 用int去声明age是一个变量,并且是一个表示整数的变量。 另外一种语言比如lua,在使用的时候并不需要预先声明其类型,他可以在程序运行的时候确定变量的类型,甚至在变量前面都不
ngx_stream_log_module 示例配置 指令 access_log log_format open_log_file_cache ngx_stream_log_module 模块(1.11.4)按指定的格式写入会话日志。 示例配置 log_format basic '$remote_addr [$time_local] ' '$protocol $s
ngx_http_random_index_module ngx_http_random_index_module 模块处理以 / 结尾的请求,然后随机选择目录中的一个文件作为索引文件展示,该模块优先于 ngx_http_index_module 之前处理。 该模块默认不会被构建到 nginx 中,需要在编译时加入 --with-http_random_index_module 配置参数启用。 配
ngx-weui 是一个使用 Angular 构建的 WeUI 组件。 在线示例以及API文档。
ngx-fastdfs 是 nginx + lua +fastdfs 实现分布式图片实时动态压缩。 install 进入docker目录docker build -t fastdfs:dev . 使用 docker -idt -p 80:80 fastdfs:dev /bin/bash进入容器执行/etc/rc.local 测试 进入容器执行test目录下的./test.sh或者直接执行下面脚本
ngx-markdown ngx-markdown is an Angular library that combines... Marked to parse markdown to HTML Prism.js for language syntax highlight Emoji-Toolkit for emoji support KaTeX for math expression rende
ngx-admin Who uses ngx-admin?| Documentation | Installation Guidelines | Angular templates New! Material theme for ngx-admin Material admin theme is based on the most popular Angular dashboard templat
@sweetalert2/ngx-sweetalert2 Official SweetAlert2 integration for Angular This is not a regular API wrapper for SweetAlert (which already works very well alone), it intends to provide Angular-esque ut
ngx-dropzone A lightweight and highly customizable Angular dropzone component for file uploads. For a demo see DEMO. And the CODE for the demo. Install $ npm install --save ngx-dropzone Usage // in ap