Add shimmer animation while book cover is loading
This commit is contained in:
+18
-12
@@ -2,23 +2,29 @@
|
||||
[class.selected]="isSelected"
|
||||
(mouseover)="isHovered = true"
|
||||
(mouseout)="isHovered = false">
|
||||
<div class="cover-container">
|
||||
<div class="cover-container" [ngClass]="{ 'shimmer': !isImageLoaded }">
|
||||
<img
|
||||
[src]="urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
class="book-cover placeholder"
|
||||
class="book-cover"
|
||||
[class.loaded]="isImageLoaded"
|
||||
alt="Cover of {{ book.metadata?.title }}"
|
||||
loading="lazy"/>
|
||||
<p-checkbox
|
||||
*ngIf="isCheckboxEnabled"
|
||||
[(ngModel)]="isSelected"
|
||||
binary="true"
|
||||
id="select-checkbox-{{book.id}}"
|
||||
class="select-checkbox"
|
||||
(ngModelChange)="toggleSelection(isSelected || false)"></p-checkbox>
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="read-btn" (click)="openBookInfo(book)"></p-button>
|
||||
<p-button [rounded]="true" icon="pi pi-book" class="info-btn" (click)="readBook(book)"></p-button>
|
||||
loading="lazy"
|
||||
(load)="onImageLoad()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p-checkbox
|
||||
*ngIf="isCheckboxEnabled"
|
||||
[(ngModel)]="isSelected"
|
||||
binary="true"
|
||||
id="select-checkbox-{{book.id}}"
|
||||
class="select-checkbox"
|
||||
(ngModelChange)="toggleSelection(isSelected || false)">
|
||||
</p-checkbox>
|
||||
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="read-btn" (click)="openBookInfo(book)"></p-button>
|
||||
<p-button [rounded]="true" icon="pi pi-book" class="info-btn" (click)="readBook(book)"></p-button>
|
||||
|
||||
<div class="book-info">
|
||||
<div class="book-title-container">
|
||||
<h4 class="book-title">{{ book.metadata?.title }}</h4>
|
||||
|
||||
+36
-6
@@ -12,6 +12,41 @@
|
||||
|
||||
.cover-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 190px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.cover-container.shimmer {
|
||||
background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 2.5s infinite linear;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
transition: opacity 0.3s ease-in;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.cover-container img.loaded {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cover-container::after {
|
||||
@@ -48,12 +83,7 @@
|
||||
padding-left: 6px;
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border-radius: 8px 8px 0 0;
|
||||
transition: filter 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
|
||||
.info-btn,
|
||||
.read-btn {
|
||||
|
||||
@@ -13,7 +13,7 @@ import {MetadataFetchOptionsComponent} from '../../../../metadata/metadata-optio
|
||||
import {MetadataRefreshType} from '../../../../metadata/model/request/metadata-refresh-type.enum';
|
||||
import {MetadataRefreshRequest} from '../../../../metadata/model/request/metadata-refresh-request.model';
|
||||
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {NgClass, NgIf} from '@angular/common';
|
||||
import {UserService} from '../../../../user.service';
|
||||
import {filter} from 'rxjs';
|
||||
|
||||
@@ -21,7 +21,7 @@ import {filter} from 'rxjs';
|
||||
selector: 'app-book-card',
|
||||
templateUrl: './book-card.component.html',
|
||||
styleUrls: ['./book-card.component.scss'],
|
||||
imports: [Button, MenuModule, CheckboxModule, FormsModule, NgIf],
|
||||
imports: [Button, MenuModule, CheckboxModule, FormsModule, NgIf, NgClass],
|
||||
standalone: true
|
||||
})
|
||||
export class BookCardComponent implements OnInit {
|
||||
@@ -32,6 +32,7 @@ export class BookCardComponent implements OnInit {
|
||||
|
||||
items: MenuItem[] | undefined;
|
||||
isHovered: boolean = false;
|
||||
isImageLoaded: boolean = false;
|
||||
|
||||
private bookService = inject(BookService);
|
||||
private dialogService = inject(DialogService);
|
||||
@@ -50,6 +51,10 @@ export class BookCardComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onImageLoad(): void {
|
||||
this.isImageLoaded = true;
|
||||
}
|
||||
|
||||
readBook(book: Book): void {
|
||||
this.bookService.readBook(book.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user