添加 LivePhoto 📷 功能

This commit is contained in:
Han 2025-03-19 20:05:47 +08:00
parent 1275760960
commit bbaa40d02d
11 changed files with 128 additions and 1 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -433,6 +433,19 @@ $\cup$、$\cap$、$\in$、$\notin$、$\ni$、$\subset$、$\subseteq$、$\supset$
![Astro主题-vhAstro-Theme](https://i0.wp.com/uxiaohan.github.io/v2/2023/03/42944511.png)
:::
### LivePhoto 组件
```md
<!-- 纵向图片 -->
::vhLivePhoto{photo="https://static.vvhan.com/img/1.webp" video="https://static.vvhan.com/img/1.mp4" type="y"}
<!-- 横向图片 -->
::vhLivePhoto{photo="https://static.vvhan.com/img/2.webp" video="https://static.vvhan.com/img/2.mp4"}
```
::vhLivePhoto{photo="/public/assets/livephoto/1.webp" video="/public/assets/livephoto/1.mp4" type="y"}
::vhLivePhoto{photo="/public/assets/livephoto/2.webp" video="/public/assets/livephoto/2.mp4"}
### Music 组件
```md

View File

@ -5,6 +5,8 @@ import codeInit from "../scripts/Code";
import videoInit from "../scripts/Video";
// 初始化音乐播放器
import musicInit from "../scripts/Music";
// 初始化 LivePhoto
import livePhotoInit from './LivePhoto'
// 初始化BackTop组件
import BackTopInitFn from "../scripts/BackTop";
// 搜索
@ -72,6 +74,8 @@ const indexInit = async (only: boolean = true) => {
videoInit(videoList);
// 文章音乐播放器初始化
musicInit(MusicList);
// 初始化 LivePhoto
livePhotoInit();
};
export default () => {

15
src/scripts/LivePhoto.ts Normal file
View File

@ -0,0 +1,15 @@
// SmoothScroll 滚动优化
import { LoadScript } from "../utils/index";
declare const LivePhotosKit: any;
export default async () => {
const livePhotoList = document.querySelectorAll('.vh-node.vh-vhLivePhoto');
if (!livePhotoList.length) return;
await LoadScript("/assets/js/livephotoskit.js");
livePhotoList.forEach((i: any) => {
const { photo, video } = i.dataset;
i.innerHTML = `<div class="live-raw"></div>`
const player = LivePhotosKit.Player(i.querySelector('.live-raw'));
player.photoSrc = photo;
player.videoSrc = video;
})
};

View File

@ -547,6 +547,34 @@ section.vh-container {
}
}
}
// ::vhLivePhoto
&.vh-vhLivePhoto {
box-sizing: border-box;
display: flex;
justify-content: center;
width: 100%;
aspect-ratio: 16 / 9;
background: #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32' width='8' height='8' fill='none' stroke='rgb(0 0 0 / 0.1)'%3e%3cpath d='M0 .5H31.5V32'/%3e%3c/svg%3e");
&.vhLivePhoto-y {
aspect-ratio: 9 / 16;
max-height: 66vh;
max-width: 100%;
}
&>div {
width: 100%;
height: 100%;
overflow: hidden;
:not(.lpk-live-photo-renderer) {
&>canvas {
z-index: 9 !important;
}
}
}
}
}
// 页面图片样式

View File

@ -186,6 +186,7 @@
bottom: -0.4rem;
width: 0.8rem;
height: 0.8rem;
border-radius: 50%;
background: #fff url("/public/assets/images/admin.svg") no-repeat;
background-size: cover;
}

View File

@ -31,7 +31,7 @@ const fmtDate = (time: string | Date, hours_status = true) => {
years && `${years}`,
months && `${months}`,
days && `${days}`,
hours_status ? hours && !years && !months && `${hours}小时` : 0,
(hours_status || days === 0) ? hours && !years && !months && `${hours}小时` : 0,
hours_status ? minutes && !years && !months && !days && `${minutes}` : '',
hours_status ? seconds && !years && !months && !days && !hours && `${seconds}` : ''
].filter(Boolean).join('');