Skip to content

Commit

Permalink
feat: article card out animation
Browse files Browse the repository at this point in the history
  • Loading branch information
KawaiiZapic committed Sep 5, 2024
1 parent 3b2d514 commit 020edc5
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 grid-gap-4">
<?php while ($this->next()){ ?>
<mdui-card clickable="false" class="flex flex-col matecho-article-card">
<a href="<?php $this->permalink(); ?>" title="<?php $this->title(); ?>" class="h-240px rounded-xl block w-full bg-center bg-cover block" style="background-image: url('<?php Matecho::cover($this);?>')"></a>
<div class="pa-4 flex-grow-1">
<a href="<?php $this->permalink(); ?>" title="<?php $this->title(); ?>" class="h-240px flex-shrink-0 block w-full bg-center bg-cover block" style="background-image: url('<?php Matecho::cover($this);?>')"></a>
<div class="matecho-article-card__meta pa-4 flex-grow-1">
<div class="text-sm mb-1 uppercase" style="color: rgb(var(--mdui-color-primary-light));">
<?php $this->category(" | "); ?>
</div>
Expand All @@ -60,7 +60,7 @@
<?php if (!$this->hidden && $this->fields->description) echo $this->fields->description; else $this->excerpt(300,'...'); ?>
</div>
</div>
<div class="flex gap-2 pl-4 pr-1 mb-2 items-center">
<div class="matecho-article-card__meta flex gap-2 pl-4 pr-1 mb-2 items-center">
<div class="flex flex-wrap flex-grow-1">
<mdui-button variant="text" class="rounded matecho-info-button" disabled>
<mdui-icon-calendar-month slot="icon"></mdui-icon-calendar-month>
Expand Down
78 changes: 78 additions & 0 deletions src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
import "virtual:components/index";
import "@/style/index.less";

export function init() {
document
.querySelectorAll("mdui-card.matecho-article-card")
.forEach(parent => {
parent.querySelectorAll("a[href]").forEach(href => {
href.addEventListener("click", () => {
const pSize = parent.getBoundingClientRect();
const placeholder = document.createElement("div");
const main =
document.querySelector<HTMLDivElement>("#matecho-pjax-main")!;
main.style.transition = ".1s";
Object.assign(placeholder.style, {
display: "block",
height: pSize.height + "px",
width: pSize.width + "px"
});
parent.after(placeholder);
Object.assign((parent as HTMLElement).style, {
height: pSize.height + "px",
width: pSize.width + "px",
left: pSize.left + "px",
top: pSize.top + "px"
});
parent.classList.add("matecho-article-card__animating");
document.body.appendChild(parent);
document.body.style.overflow = "hidden";
requestAnimationFrame(() => {
main.style.opacity = "0";
document.body.classList.add("matecho-article-animation__running");
Object.assign((parent as HTMLElement).style, {
height: "",
width: "",
left: "",
top: ""
});
});
document.addEventListener(
"pjax:complete",
() => {
document.body.style.overflow = "";
(parent as HTMLElement).style.position = "absolute";
const main = document.querySelector("#matecho-pjax-main");
if (
!main ||
!main.parentElement ||
main.querySelector("#matecho-password-form")
) {
parent.remove();
return;
}
const ob = new MutationObserver(() => {
if (!main.parentElement) {
ob.disconnect();
parent.remove();
return;
}
});
ob.observe(main.parentElement, {
childList: true
});
document
.querySelector("#matecho-pjax-main")
?.addEventListener("animationend", () => {
parent.remove();
ob.disconnect();
document.body.classList.remove(
"matecho-article-animation__running"
);
});
},
{ once: true }
);
});
});
});
}
6 changes: 3 additions & 3 deletions src/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<?php if (!$this->hidden) { ?>
<div id="matecho-app-bar-large-label">
<div class="box-border pr-2 pl-4 md:pl-0 " id="matecho-app-bar-large-label__inner">
<div class="text-sm mb-2 uppercase" style="color: rgb(var(--mdui-color-primary-light));">
<div class="text-sm mb-2 uppercase h-5" style="color: rgb(var(--mdui-color-primary-light));">
<?php $this->category(" | "); ?>
</div>
<div class="truncate text-3xl md:text-5xl line-height-[1.4]!">
<?php $this->title(); ?>
</div>
<div class="text-sm opacity-80 block mt-3 truncate">
<div class="text-sm opacity-80 block mt-3 truncate h-5">
<?php
if ($this->archiveType === 'post') {
if (!$this->hidden && $this->fields->description) {
Expand All @@ -26,7 +26,7 @@
</div>
</div>
</div>
<div class="mb-8 md:rounded-xl transition block h-240px w-full overflow-hidden bg-center bg-cover"
<div class="matecho-article-cover mb-8 md:rounded-xl transition block h-240px w-full overflow-hidden bg-center bg-cover"
style="background-image: url('<?php Matecho::cover($this); ?>')">
</div>
<div class="w-full px-4 box-border">
Expand Down
44 changes: 44 additions & 0 deletions src/style/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.matecho-article-card__animating {
position: fixed;
pointer-events: none;
transition:
height 0.3s,
width 0.3s,
top 0.3s,
left 0.2s,
background-color 0s 0.3s,
border-radius 0.3s;
width: 824px;
height: 240px;
top: 223px;
left: calc((100% - 824px) / 2);
background-color: transparent;
box-shadow: none;

& .matecho-article-card__meta {
animation: fade-out 0.3s forwards;
}
}

@media (width <= 840px) {
.matecho-article-card__animating {
width: 100%;
top: 198px;
left: 0;
border-radius: 0;
}
}

.matecho-article-animation__running .matecho-article-cover {
visibility: hidden;
}

@keyframes fade-out {
from {
opacity: 1;
}

to {
opacity: 0;
}
}

0 comments on commit 020edc5

Please sign in to comment.