相册动画

This commit is contained in:
tangly1024
2022-05-06 14:07:08 +08:00
parent 4be70baa19
commit ff191ea07c

View File

@@ -2,6 +2,7 @@ import { NotionRenderer } from 'react-notion-x'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import mediumZoom from 'medium-zoom' import mediumZoom from 'medium-zoom'
import React from 'react' import React from 'react'
import anime from 'animejs'
const Code = dynamic(() => const Code = dynamic(() =>
import('react-notion-x/build/third-party/code').then((m) => m.Code), { ssr: false } import('react-notion-x/build/third-party/code').then((m) => m.Code), { ssr: false }
@@ -31,29 +32,41 @@ const NotionPage = ({ post }) => {
background: 'rgba(0, 0, 0, 0.2)', background: 'rgba(0, 0, 0, 0.2)',
margin: getMediumZoomMargin() margin: getMediumZoomMargin()
}) })
const zoomRef = React.useRef(zoom ? zoom.clone() : null) const zoomRef = React.useRef(zoom ? zoom.clone() : null)
React.useEffect(() => {
anime({
targets: 'div:not(.notion-viewport)', // 动效不能加载图片缩放遮罩上。
keyframes: [
{ translateY: 40 },
{ translateY: 0 }
],
duration: 3000,
easing: 'easeInOutSine'
})
}, [])
setTimeout(() => { setTimeout(() => {
if (typeof document === 'undefined') { if (typeof document !== 'undefined') {
return const buttons = document.getElementsByClassName('notion-code-copy')
} for (const e of buttons) {
const buttons = document.getElementsByClassName('notion-code-copy') e.addEventListener('click', fixCopy)
for (const e of buttons) { }
e.addEventListener('click', fixCopy) // 将相册gallery下的图片加入放大功能
} // const container = document?.getElementById('container')
// 将所有container下的所有图片添加medium-zoom const imgList = document?.querySelectorAll('.notion-collection-card-cover img')
const container = document?.getElementById('container') if (imgList && zoomRef.current) {
const imgList = container?.getElementsByTagName('img') for (let i = 0; i < imgList.length; i++) {
if (imgList && zoomRef.current) { (zoomRef.current).attach(imgList[i])
for (let i = 0; i < imgList.length; i++) { }
(zoomRef.current).attach(imgList[i]) }
const cards = document.getElementsByClassName('notion-collection-card')
for (const e of cards) {
e.removeAttribute('href')
} }
} }
const cards = document.getElementsByClassName('notion-collection-card') }, 800)
for (const e of cards) {
e.removeAttribute('href')
}
}, 500)
/** /**
* 复制代码后,会重复 @see https://github.com/tangly1024/NotionNext/issues/165 * 复制代码后,会重复 @see https://github.com/tangly1024/NotionNext/issues/165