Skip to content

Commit

Permalink
Merge pull request tangly1024#2381 from tangly1024/feat/mouse-follow
Browse files Browse the repository at this point in the history
鼠标跟随动画
  • Loading branch information
tangly1024 authored May 6, 2024
2 parents 4d6ffad + e553c75 commit 6cbb256
Show file tree
Hide file tree
Showing 4 changed files with 753 additions and 1 deletion.
7 changes: 7 additions & 0 deletions blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ const BLOG = {
'251, 243, 140'
],

// 鼠标跟随特效
MOUSE_FOLLOW: process.env.NEXT_PUBLIC_MOUSE_FOLLOW || true, // 开关
// 这两个只有在鼠标跟随特效开启时才生效
// 鼠标类型 1:路劲散点 2:下降散点 3:上升散点 4:边缘向鼠标移动散点 5:跟踪转圈散点 6:路径线条 7:聚集散点 8:聚集网格 9:移动网格 10:上升粒子 11:转圈随机颜色粒子 12:圆锥放射跟随蓝色粒子
MOUSE_FOLLOW_EFFECT_TYPE: 11, // 1-12
MOUSE_FOLLOW_EFFECT_COLOR: '#ef672a', // 鼠标点击特效颜色 #xxxxxx 或者 rgba(r,g,b,a)

// 樱花飘落特效
SAKURA: process.env.NEXT_PUBLIC_SAKURA || false, // 开关
// 漂浮线段特效
Expand Down
6 changes: 5 additions & 1 deletion components/ExternalPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const ThemeSwitch = dynamic(() => import('@/components/ThemeSwitch'), {
const Fireworks = dynamic(() => import('@/components/Fireworks'), {
ssr: false
})
const MouseFollow = dynamic(() => import('@/components/MouseFollow'), {
ssr: false
})
const Nest = dynamic(() => import('@/components/Nest'), { ssr: false })
const FlutteringRibbon = dynamic(
() => import('@/components/FlutteringRibbon'),
Expand Down Expand Up @@ -119,6 +122,7 @@ const ExternalPlugin = props => {
const CLARITY_ID = siteConfig('CLARITY_ID')
const IMG_SHADOW = siteConfig('IMG_SHADOW')
const ANIMATE_CSS_URL = siteConfig('ANIMATE_CSS_URL')
const MOUSE_FOLLOW = siteConfig('MOUSE_FOLLOW')

// 自定义样式css和js引入
if (isBrowser) {
Expand Down Expand Up @@ -172,7 +176,7 @@ const ExternalPlugin = props => {
<>
{/* 全局样式嵌入 */}
<GlobalStyle />

{MOUSE_FOLLOW && <MouseFollow />}
{THEME_SWITCH && <ThemeSwitch />}
{DEBUG && <DebugPanel />}
{ANALYTICS_ACKEE_TRACKER && <Ackee />}
Expand Down
27 changes: 27 additions & 0 deletions components/MouseFollow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useEffect } from 'react'
// import anime from 'animejs'
import { siteConfig } from '@/lib/config'
import { loadExternalResource } from '@/lib/utils'

/**
* 鼠标跟随特效
* @returns
*/
const MOUSE_FOLLOW = () => {
const type = siteConfig('MOUSE_FOLLOW_EFFECT_TYPE')
const color = siteConfig('MOUSE_FOLLOW_EFFECT_COLOR')

useEffect(() => {
loadExternalResource('/js/mouse-follow.js', 'js').then(url => {
if (window.createMouseCanvas) {
window.createMouseCanvas()({
type,
color
})
}
})
}, [])

return <></>
}
export default MOUSE_FOLLOW
Loading

0 comments on commit 6cbb256

Please sign in to comment.