vuepress-theme-reco/components/Background.vue

125 lines
2.7 KiB
Vue
Raw Normal View History

2019-04-15 10:35:40 +08:00
<template>
<div id="particles-oli-wrapper"></div>
</template>
<script>
export default {
2019-08-12 10:31:23 +08:00
mounted () {
const keyPage = this.$themeConfig.keyPage
let color = '#424242'
let lineColor = '#424242'
2019-08-12 10:31:23 +08:00
const num = 20
if (keyPage) {
color = keyPage.color || color
lineColor = keyPage.lineColor || lineColor
}
2019-08-12 10:31:23 +08:00
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js'
2019-04-15 10:35:40 +08:00
2019-08-12 10:31:23 +08:00
document.body.append(script)
script.onload = function () {
const particlesJS = window.particlesJS
particlesJS('particles-oli-wrapper', {
2019-04-15 10:35:40 +08:00
particles: {
number: {
2019-08-12 10:31:23 +08:00
value: num,
2019-04-15 10:35:40 +08:00
density: {
enable: true,
value_area: 800
}
},
color: {
value: color
},
shape: {
2019-08-12 10:31:23 +08:00
type: 'circle',
2019-04-15 10:35:40 +08:00
stroke: {
width: 0,
2019-08-12 10:31:23 +08:00
color: '#000000'
2019-04-15 10:35:40 +08:00
},
polygon: {
nb_sides: 5
}
},
opacity: {
2019-08-12 10:31:23 +08:00
value: 0.9,
2019-04-15 10:35:40 +08:00
random: false,
anim: {
enable: false,
speed: 1,
2019-08-12 10:31:23 +08:00
opacity_min: 0.6,
2019-04-15 10:35:40 +08:00
sync: false
}
},
size: {
2019-08-12 10:31:23 +08:00
value: 3,
2019-04-15 10:35:40 +08:00
random: true,
anim: {
enable: false,
speed: 30,
size_min: 0.1,
sync: false
}
},
line_linked: {
enable: true,
distance: 250,
color: lineColor,
2019-08-12 10:31:23 +08:00
opacity: 0.4,
2019-04-15 10:35:40 +08:00
width: 1
},
move: {
enable: true,
speed: 3,
2019-08-12 10:31:23 +08:00
direction: 'none',
2019-04-15 10:35:40 +08:00
random: true,
straight: false,
2019-08-12 10:31:23 +08:00
out_mode: 'out',
2019-04-15 10:35:40 +08:00
bounce: true,
attract: {
enable: false,
rotateX: 600,
rotateY: 1200
}
}
},
interactivity: {
2019-08-12 10:31:23 +08:00
detect_on: 'canvas',
2019-04-15 10:35:40 +08:00
events: {
onhover: {
enable: true,
2019-08-12 10:31:23 +08:00
mode: 'grab'
2019-04-15 10:35:40 +08:00
},
onclick: {
enable: true,
2019-08-12 10:31:23 +08:00
mode: 'push'
2019-04-15 10:35:40 +08:00
},
resize: true
},
modes: {
grab: {
distance: 100,
line_linked: {
opacity: 0.5
}
}
}
},
retina_detect: true
2019-08-12 10:31:23 +08:00
})
}
2019-04-15 10:35:40 +08:00
}
2019-08-12 10:31:23 +08:00
}
2019-04-15 10:35:40 +08:00
</script>
<style lang='stylus' scoped>
2019-04-15 10:35:40 +08:00
#particles-oli-wrapper {
2019-08-12 10:31:23 +08:00
position: absolute;
z-index: -1;
top: 0;
width: 100%;
2019-04-15 10:35:40 +08:00
height: 99vh;
}
</style>