Open ananddharne opened 7 years ago
You should call particlesJS inside mounted() event
How exactly? Any help would be appreciated. I am a beginner
. I am using webpack with vue cli. This is my component App.vue. I did an npm install particlesjs and imported using 'from' as seen below Ap.vue component where I want to load particles.js at root
`
<template>
<div id="app">
<div id="particles-js"></div>
<router-link to = "/"> Home </router-link>
<router-view></router-view>
</div>
</template>
<script>
/* eslint-disable */
import particles from 'particles.js'
export default {
name: 'app',
mounted()
{
console.log('mounted');
particlesJS('app', {
"particles": {
"number": {
"value": 380,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "img/github.svg",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 6,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": true,
"mode": "grab"
},
"onclick": {
"enable": true,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 140,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
});
}
}
/* eslint-disable */
</script>
<style>
#app {
position: absolute;
width: 100%;
height: 100%;
}
canvas {
display: block;
vertical-align: bottom;
}
</style>
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>portfolio2</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.0/css/bulma.css">
</head>
<body>
<div id="app"></div>
<div id="particles-js"></div>
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
</body>
</html>
main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
index.js(routing)
/* eslint-disable */
import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello'
import Home from '@/components/Home'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Hello',
component: Hello
},
{
path: '/',
name: 'Home',
component: Home
}
]
})
The particles.js doesnt load up everything else works. When I go into console I can also see a container of canvas. What is it I that I am doing wrong? Any help would be greatly appreciated! Link to output - http://imgur.com/a/qaYzF. `
I can run it here, I guess it is possible that your background is white. You can try:
width: 100%;
height: 100%;
background: cornflowerblue;
}
I have implemented it but the problem is that it is not acting as a background
I have been trying to use this but I am not able to get this right