Skip to content

Commit

Permalink
feat: create vuepress-plugin-bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
xcyeye committed Nov 21, 2021
1 parent ee70253 commit 5a0a19e
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 18 deletions.
56 changes: 56 additions & 0 deletions Aurora-plugin/vuepress-plugin-bubble/lib/AuroraBubble.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<div class="aurora-bubble">
<div class="aurora-bubble-box" id="aurora-bubble-box"></div>
<canvas class="aurora-bubble-canvas" id="aurora-bubble-canvas"></canvas>
</div>
</template>

<script>
//获取用户传入的配置
let bubbleNumber = 0.15
let bubbleAlpha = 0.7
let alphaChangeSpeed = 0.0005
let size = 0.5
let sizeChangeSpeed = 0.002
let riseSpeed = 0.9
let color = '255,255,255'
try {
bubbleNumber = __BUBBLE_NUMBER__
bubbleAlpha = __BUBBLE_ALPHA__
alphaChangeSpeed = __ALPHA_CHANGE_SPEED__
size = __SIZE__
sizeChangeSpeed = __SIZE_CHANGE_SPEED__
riseSpeed = __RISE_SPEED__
color = __COLOR__
}catch (e) {
console.warn(e)
}
const bubble = require('./bubble')
export default {
name: "AuroraBubble",
mounted() {
bubble.bubble(bubbleNumber,bubbleAlpha,alphaChangeSpeed,size,sizeChangeSpeed,riseSpeed,color)
}
}
</script>

<style lang="css" scoped>
.aurora-bubble {
position: fixed;
top: 0;
right: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.aurora-bubble-box,.aurora-bubble-canvas {
width: 100%;
height: 100%;
position: absolute;
top: 0;
/*background: red;*/
}
</style>
89 changes: 89 additions & 0 deletions Aurora-plugin/vuepress-plugin-bubble/lib/bubble.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* 这个气泡特效是收集于网络,作者为一为忆, http://www.iowen.cn */
let canvas, ctx, width, height, bubbles, animateHeader = true;
let bubbleNumber,bubbleAlpha,alphaChangeSpeed,size,sizeChangeSpeed,riseSpeed,color;
function initHeader() {
canvas = document.getElementById('aurora-bubble-canvas');
window_resize();
ctx = canvas.getContext('2d');
//建立泡泡
bubbles = [];
let num = width * bubbleNumber;//气泡数量
for (let i = 0; i < num; i++) {
let c = new Bubble();
bubbles.push(c);
}
animate();
}

function animate() {
if (animateHeader) {
ctx.clearRect(0, 0, width, height);
for (let i in bubbles) {
bubbles[i].draw();
}
}
requestAnimationFrame(animate);
}

function window_resize() {
//canvas铺满窗口
width = window.innerWidth;
height = window.innerHeight;

//如果需要铺满内容可以换下面这个
let panel = document.getElementById('aurora-bubble-box');
width=panel.offsetWidth;
height=panel.offsetHeight;

canvas.width = width;
canvas.height = height;
}

window.onresize = function(){
window_resize();
}

function Bubble() {
let _this = this;
(function() {
_this.pos = {};
init();
})();
function init() {
_this.pos.x = Math.random() * width;
_this.pos.y = height + Math.random() * 100;
_this.alpha = 0.1 + Math.random() * bubbleAlpha;//气泡透明度
_this.alpha_change = 0.0002 + Math.random() * alphaChangeSpeed;//气泡透明度变化速度
_this.scale = 0.2 + Math.random() * size;//气泡大小
_this.scale_change = Math.random() * sizeChangeSpeed;//气泡大小变化速度
_this.speed = 0.1 + Math.random() * riseSpeed;//气泡上升速度
}
//气泡
this.draw = function() {
if (_this.alpha <= 0) {
init();
}
_this.pos.y -= _this.speed;
_this.alpha -= _this.alpha_change;
_this.scale += _this.scale_change;
ctx.beginPath();
ctx.arc(_this.pos.x, _this.pos.y, _this.scale * 10, 0, 2 * Math.PI, false);
ctx.fillStyle = 'rgba(' + color + ',' + _this.alpha + ')';
ctx.fill();
};
}


module.exports = {
bubble: function (aurora_bubbleNumber,aurora_bubbleAlpha,aurora_alphaChangeSpeed,aurora_size,aurora_sizeChangeSpeed,aurora_riseSpeed,aurora_color) {
bubbleNumber = aurora_bubbleNumber
bubbleAlpha = aurora_bubbleAlpha
alphaChangeSpeed = aurora_alphaChangeSpeed
size = aurora_size
sizeChangeSpeed = aurora_sizeChangeSpeed
riseSpeed = aurora_riseSpeed
color = aurora_color

initHeader();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const _default: import("@vuepress/client").ClientAppEnhance;
export default _default;

4 changes: 4 additions & 0 deletions Aurora-plugin/vuepress-plugin-bubble/lib/clientAppEnhance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineClientAppEnhance } from '@vuepress/client';
export default defineClientAppEnhance(({ app, router }) => {

});
3 changes: 3 additions & 0 deletions Aurora-plugin/vuepress-plugin-bubble/lib/node/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { BubblePluginOptions } from './vuepress-plugin-bubble';
export * from './vuepress-plugin-bubble';
export default BubblePluginOptions;
15 changes: 15 additions & 0 deletions Aurora-plugin/vuepress-plugin-bubble/lib/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
const bubblePlugin_1 = require("./vuepress-plugin-bubble");
__exportStar(require("./vuepress-plugin-bubble"), exports);
exports.default = bubblePlugin_1.bubblePlugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { Plugin } from '@vuepress/core';
export declare type BubblePluginOptions = Record<never, never>;
export declare const BubblePluginOptions: Plugin<BubblePluginOptions>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cozePlugin = void 0;
const { path } = require('@vuepress/utils')
const utils_1 = require("@vuepress/utils");
const vuepressPluginBubble = ({bubbleNumber,bubbleAlpha,alphaChangeSpeed,size,sizeChangeSpeed,riseSpeed,color}) => {
return {
onInitialized: (app) => {

},
name: 'vuepress-plugin-bubble',
define: {
__BUBBLE_NUMBER__: bubbleNumber,
__BUBBLE_ALPHA__: bubbleAlpha,
__ALPHA_CHANGE_SPEED__: alphaChangeSpeed,
__SIZE__: size,
__SIZE_CHANGE_SPEED__: sizeChangeSpeed,
__RISE_SPEED__: riseSpeed,
__COLOR__: color
},
multiple: false,
clientAppEnhanceFiles: utils_1.path.resolve(__dirname, '../clientAppEnhance.js'),
clientAppRootComponentFiles: path.resolve(__dirname, '../AuroraBubble.vue'),
};
};
exports.bubblePlugin = vuepressPluginBubble;
6 changes: 3 additions & 3 deletions Aurora-theme/lib/client/components/child/home/StyleMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="welcome-parent" id="welcome-parent">
<div @click="clickSet" :class="customClass" :style="getColorStyle" class="m-4 p-4 f4 color-shadow-small bg-gray-800-mktg rounded-2 signup-content-container welcome" id="welcome">
<span @click="clickSetColor" class="cancel aurora-iconfont-common aurora-style-cancel" id="cancel"></span>
<h1 class="common-style" id="sr-only-h2">Welcome to my blog! <br>Let's begin the adventure</h1>
<h1 class="common-style" id="sr-only-h2"></h1>
<div class="custom-top custom-common">
<div class="custom-top-span custom-common-span">
<span @click="setImg" class="aurora-iconfont-common aurora-style-img home-welcome-custom-icon"></span>&nbsp;
Expand Down Expand Up @@ -51,7 +51,7 @@
</div>
</div>
</div>
<div class="custom-bottom custom-common">
<!--<div class="custom-bottom custom-common">
<div class="custom-bottom-span custom-common-span">
模糊度
</div>
Expand All @@ -65,7 +65,7 @@
</div>
</div>
</div>
</div>
</div>-->
<div class="custom-bottom custom-common">
<div class="custom-bottom-span custom-common-span">
透明度
Expand Down
7 changes: 2 additions & 5 deletions Aurora-theme/lib/client/components/global/Common.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,9 @@
:is-show-footer="isShowFooter">
</Footer>
</div>
<div id="set-bg"
:chu="$store.state.homeWps"
:class="{'set-bg-fitter': $store.state.isFitter}"
<div id="set-bg" class="set-bg-fitter"
:style="'--opacity: ' + $store.state.varOpacity +
'; --fitter-blue: ' + $store.state.varFilterBlur +
'px; --borderRadius: ' + $store.state.varBorderRadius +
'; --borderRadius: ' + $store.state.varBorderRadius +
'px; --backgroundImageUrl: url(' + $store.state.homeWps + ')'"
></div>
<div id="posterShade" :class="{posterShade: $store.state.showPosterShadow}">
Expand Down
15 changes: 6 additions & 9 deletions Aurora-theme/lib/client/styles/theme.style.css
Original file line number Diff line number Diff line change
Expand Up @@ -925,16 +925,13 @@ a[data-v-d8ec41bc] {
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
-webkit-filter: blur(var(--fitter-blue));
filter: blur(var(--fitter-blue));
/*-webkit-filter: blur(var(--fitter-blue));*/
/*filter: blur(var(--fitter-blue));*/
z-index: -2;
}

.set-bg-fitter:before {
content: "";
background-image: var(--backgroundImageUrl);
background-repeat: no-repeat;
background-size: cover;
/*background-image: var(--backgroundImageUrl);*/
/*background-repeat: no-repeat;*/
/*background-size: cover;*/
background: rgba(0,0,0,.15);
}

.el-pager li {
Expand Down
26 changes: 26 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,32 @@ module.exports = {
excludes: ['/footer.html','/404.html','/about/','/mood/','/link/','/tag/','/photo/'],
noTitle: '暂时没有标题配置'
}*/

[
path.resolve(__dirname, "../../Aurora-plugin/vuepress-plugin-bubble/lib/node/index.js"),
{
//气泡数量 推荐0(不包括)到1之前的小数,
bubbleNumber: 0.14,

//气泡透明度 0到1之间的小数
bubbleAlpha: 0.6,

//透明度变化速度,越接近于0越好
alphaChangeSpeed: 0.00001,

//气泡大小,推荐0到1之间的值
size: 0.4,

//气泡大小变化速度 越小越好
sizeChangeSpeed: 0.0002,

//气泡上升速度
riseSpeed: 0.4,

//气泡颜色,白色rgb(255,255,255) 请传入255,255,255
color: '255,255,255'
}
],
],
//设置head 一定要加入<script src="https://at.alicdn.com/t/font_2849934_v6y652peian.js"></script>项配置,否则一些图标不能正常显示
head: [
Expand Down
2 changes: 1 addition & 1 deletion docs/.vuepress/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@


body::-webkit-scrollbar {
display: none;
/*display: none;*/
}

0 comments on commit 5a0a19e

Please sign in to comment.