StarBlog Development Notes (10): Image Display - Waterfall Layout - Homepage Cards
Series Articles Developing Blog Project StarBlog with .NetCore - (1) Why Do You Need to Write Your Own Blog? Developing Blog Project StarBlog with .NetCore - (2) Environment Setup and Creating the Project Developing Blog Project StarBlog with .NetCore - (3) Model Design Developing Blog Project StarBlog with .NetCore - (4) Batch Import of Markdown Blogs Developing Blog Project StarBl
目录8 个章节
Series Articles
- Developing Blog Project StarBlog with .NetCore - (1) Why Do You Need to Write Your Own Blog?
- Developing Blog Project StarBlog with .NetCore - (2) Environment Setup and Creating the Project
- Developing Blog Project StarBlog with .NetCore - (3) Model Design
- Developing Blog Project StarBlog with .NetCore - (4) Batch Import of Markdown Blogs
- Developing Blog Project StarBlog with .NetCore - (5) Starting to Build the Web Project
- Developing Blog Project StarBlog with .NetCore - (6) Page Development: Blog Post List
- Developing Blog Project StarBlog with .NetCore - (7) Page Development: Post Detail Page
- Developing Blog Project StarBlog with .NetCore - (8) Displaying Category Hierarchy
- Developing Blog Project StarBlog with .NetCore - (9) Batch Image Import
- Developing Blog Project StarBlog with .NetCore - (10) Image Waterfall Layout
- ...
Preface
The previous article covered batch image import. I saw some readers commenting asking why there was no introduction to uploading images, so let me explain: the order of this series is:
- From the blog frontend to the admin backend
- From backend C# code to frontend Vue+ElementUI
So the image upload part will be covered later in the admin backend development. Stay tuned~
Picking up from the previous article, I’ll continue covering the photography module. After images are imported, they need to be displayed. This article covers (filler) implementing the image waterfall layout.
PS: The techniques involved are quite simple, so this article will be a bit lightweight. Feel free to skip it if you’re a pro~
Take a Look at the Result First
I imported some wallpapers collected by a crawler as test data. Let’s look at the waterfall layout first.

Admin backend waterfall layout

This is the homepage card effect

Implementation
The waterfall layout principle is simple, and there are plenty of ready-made wheels to use, so I won’t reinvent the wheel (just copy-paste) haha
Frontend
For the blog frontend waterfall layout I chose masonry-layout. Project homepage: https://github.com/desandro/masonry
I picked this component because I saw Bootstrap 5’s example code using it for the waterfall layout, so I just copied it over (flees)
Usage is very simple
<div class="row" data-masonry='{"percentPosition": true }'>
@foreach (var photo in Model.Photos) {
<div class="col-sm-6 col-lg-4 mb-4">
<partial name="Widgets/PhotoCard" model="photo"/>
</div>
}
</div>
There are many options you can configure; I didn’t look into them in depth
Its GitHub homepage doesn’t really introduce it much either; the docs are all on the official site: https://masonry.desandro.com/
The official site’s style is quite distinctive too (flees)
Admin Backend
The admin backend waterfall layout is implemented with the vue-waterfall component, which I’ll cover in a later article~
Finally, these homepage cards were also tweaked from Bootstrap 5 examples
The code is as follows
@model Photo
<div class="card card-cover h-100 overflow-hidden text-white bg-dark rounded-5 shadow-lg"
style="background-image: url('media/@Model.FilePath.Replace("\\", "/")');">
<div class="d-flex flex-column h-100 p-5 pb-3 text-white text-shadow-1">
<h2 class="pt-5 mt-5 mb-5 display-6 lh-1 fw-bold">
@Model.Title
<p></p>
</h2>
<ul class="d-flex list-unstyled mt-auto">
<li class="me-auto">
<img src="~/images/star.jpg" alt="Bootstrap" width="32" height="32" class="rounded-circle border border-white">
</li>
<li class="d-flex align-items-center me-3">
<span class="bi me-2">
<i class="fa-solid fa-location-pin"></i>
</span>
<small>@Model.Location</small>
</li>
<li class="d-flex align-items-center">
<span class="bi me-2">
<i class="fa-solid fa-calendar-days"></i>
</span>
<small>@Model.CreateTime.ToShortDateString()</small>
</li>
</ul>
</div>
</div>
Done~
Advanced
The frontend uses masonry + infinite-scroll to implement load-on-scroll
You must use the imagesLoaded library to handle events after images load. Official site: https://imagesloaded.desandro.com/
Closing
Today happens to be June 1st Children’s Day. I saw lots of kids out playing on the street — wonderful. Wishing all the grown-ups and little ones happiness every day~
_EOF_
StarBlog Development Notes (10): Image Display - Waterfall Layout - Homepage Cards
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
StarBlog博客开发笔记(22):开发博客文章相关接口
前言 本文介绍博客文章相关接口的开发,作为接口开发介绍的第一篇,会写得比较详细,以抛砖引玉,后面的其他接口就粗略带过了,着重于WebApi开发的周边设施。 涉及到的接口:文章CRUD、置顶文章、推荐文章等。 开始前先介绍下AspNetCore框架的基础概念,MVC模式(前后端不分离)、WebApi模式(前后端分离),都是有Controller的。 区别在前者的Controller集成自 Contr
2023-01-02 · StarBlog博客开发笔记 · 约 1 分钟
StarBlog开源博客项目 - 2023年底更新内容一览
前台UI勉强能看,后台总算不那么辣眼睛了。数据库分页改对了,不然性能差得离谱。新增slug检查?哦,终于知道避免重复了。
2023-12-16 · StarBlog博客开发笔记 · 约 1 分钟
StarBlog博客开发笔记(23):文章列表接口分页、过滤、搜索、排序
前言 上一篇留的坑,火速补上。 在之前的第6篇中,已经有初步介绍,本文做一些补充,已经搞定这部分的同学可以快速跳过,基于.NetCore开发博客项目 StarBlog - (6) 页面开发之博客文章列表 对标准的WebApi来说,分页、过滤、搜索、排序是很常见的功能,既可以方便用户查看数据,又可以提升程序性能。 通用请求参数 定义一个类来作为通用的请求参数 列表接口通用的参数是这几个:PageSi
2023-01-02 · StarBlog博客开发笔记 · 约 1 分钟
StarBlog博客开发笔记(20):图片显示优化
前言 我的服务器带宽比较高,博客部署在上面访问的时候几乎没感觉有加载延迟,就没做图片这块的优化,不过最近有小伙伴说博客的图片加载比较慢,那就来把图片优化完善一下吧~ 目前有两个地方需要完善 图片瀑布流 图片缩略图 图片瀑布流 关于瀑布流之前的文章有介绍: 基于.NetCore开发博客项目 StarBlog - (10) 图片瀑布流 不过当时直接套用的 Bootstrap5 例子代码,有偶尔显示错位
2022-11-27 · StarBlog博客开发笔记 · 约 1 分钟
讨论
共 0 条加载评论中…