I have seen other questions on StackOverflow about this but none of them covered my error. I am building a web app on React and thought everything was ok until I realized that when I press F11 and go fullscreen particles.js doesnt cover the whole background. This is even more noticeable when playing with responsiveness. Driving me insane since I tried all the CSS configurations I saw here.
Here is my app.css
code:
/* Styles go here */
#account{
font-size: 0.9rem;
color: aliceblue;
}
.mi-navbar{
height: 60px;
}
.mi-tabla{
margin-top: 70px;
}
html, body {
background-color: black;
height: 25px;
}
p{
color: aliceblue;
}
canvas {
display: block;
vertical-align: bottom;
}
#particles-js {
position: absolute;
width: 100%;
height: 100vh;
}
.main-content{
overflow: hidden;
height: 100vh;
}
#loader{
margin-top: 270px;
text-align: center;
font-size: 2rem;
}
My App.js
file: (probably only relevant at the render and return functions)
import React, { Component } from 'react'
import Web3 from 'web3'
import DaiToken from '../abis/DaiToken.json'
import DappToken from '../abis/DappToken.json'
import TokenFarm from '../abis/TokenFarm.json'
import Navbar from './Navbar'
import Main from './Main'
import './App.css'
import ParticleBackground from '../particleBackground'
class App extends Component {
async componentWillMount() {
await this.loadWeb3()
await this.loadBlockchainData()
}
async loadBlockchainData() {
const web3 = window.web3
const accounts = await web3.eth.getAccounts()
this.setState({ account: accounts[0] })
const networkId = await web3.eth.net.getId()
// Load DaiToken
const daiTokenData = DaiToken.networks[networkId]
if(daiTokenData) {
const daiToken = new web3.eth.Contract(DaiToken.abi, daiTokenData.address)
this.setState({ daiToken })
let daiTokenBalance = await daiToken.methods.balanceOf(this.state.account).call()
this.setState({ daiTokenBalance: daiTokenBalance.toString() })
} else {
window.alert('DaiToken contract not deployed to detected network.')
}
// Load DappToken
const dappTokenData = DappToken.networks[networkId]
if(dappTokenData) {
const dappToken = new web3.eth.Contract(DappToken.abi, dappTokenData.address)
this.setState({ dappToken })
let dappTokenBalance = await dappToken.methods.balanceOf(this.state.account).call()
this.setState({ dappTokenBalance: dappTokenBalance.toString() })
} else {
window.alert('DappToken contract not deployed to detected network.')
}
// Load TokenFarm
const tokenFarmData = TokenFarm.networks[networkId]
if(tokenFarmData) {
const tokenFarm = new web3.eth.Contract(TokenFarm.abi, tokenFarmData.address)
this.setState({ tokenFarm })
let stakingBalance = await tokenFarm.methods.stakingBalance(this.state.account).call()
this.setState({ stakingBalance: stakingBalance.toString() })
} else {
window.alert('TokenFarm contract not deployed to detected network.')
}
this.setState({ loading: false })
}
async loadWeb3() {
if (window.ethereum) {
window.web3 = new Web3(window.ethereum)
await window.ethereum.enable()
}
else if (window.web3) {
window.web3 = new Web3(window.web3.currentProvider)
}
else {
window.alert('Non-Ethereum browser detected. You should consider trying MetaMask!')
}
}
stakeTokens = (amount) => {
this.setState({ loading: true })
this.state.daiToken.methods.approve(this.state.tokenFarm._address, amount).send({ from: this.state.account }).on('transactionHash', (hash) => {
this.state.tokenFarm.methods.stakeTokens(amount).send({ from: this.state.account }).on('transactionHash', (hash) => {
this.setState({ loading: false })
})
})
}
unstakeTokens = (amount) => {
this.setState({ loading: true })
this.state.tokenFarm.methods.unstakeTokens().send({ from: this.state.account }).on('transactionHash', (hash) => {
this.setState({ loading: false })
})
}
constructor(props) {
super(props)
this.state = {
account: '0x0',
daiToken: {},
dappToken: {},
tokenFarm: {},
daiTokenBalance: '0',
dappTokenBalance: '0',
stakingBalance: '0',
loading: true
}
}
render() {
let content
//CHANGED THIS.STATE.LOADING TO FALSE SO THAT APP WORKS WITHOUT GANACHE (BUT WONT BE ABLE TO STAKE TOKENS)
if(this.state.loading == false) {
content = <p id="loader" className="text-center">Loading...</p>
} else {
content = <Main
daiTokenBalance={this.state.daiTokenBalance}
dappTokenBalance={this.state.dappTokenBalance}
stakingBalance={this.state.stakingBalance}
stakeTokens={this.stakeTokens}
unstakeTokens={this.unstakeTokens}
/>
}
return (
<div>
<Navbar account={this.state.account} />
<ParticleBackground/>
<div className="main-content">
<div className="container-fluid mt-5">
<div className="row">
<main role="main" className="col-lg-12 ml-auto mr-auto" style={{ maxWidth: '600px' }}>
<div className="content mr-auto ml-auto">
<a
href="#"
target="_blank"
rel="noopener noreferrer"
>
</a>
{content}
</div>
</main>
</div>
</div>
</div>
</div>
);
}
}
export default App;
My particles
component:
import React from "react"
import Particles from 'react-particles-js';
import particleConfig from './config/particle-config';
export default function ParticleBackground() {
return (
<>
<div id="particles-js">
<Particles params={particleConfig}></Particles>
</div>
</>
);
}
and my particles-config.js
file:
const particleConfig = {
particles: {
number: {
value: 160,
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: 1,
random: true,
anim: {
enable: true,
speed: 1,
opacity_min: 0,
sync: false
}
},
size: {
value: 3,
random: true,
anim: {
enable: false,
speed: 4,
size_min: 0.3,
sync: false
}
},
line_linked: {
enable: false,
distance: 150,
color: "#ffffff",
opacity: 0.4,
width: 1
},
move: {
enable: true,
speed: 1,
direction: "none",
random: true,
straight: false,
out_mode: "out",
bounce: false,
attract: {
enable: false,
rotateX: 600,
rotateY: 600
}
}
},
interactivity: {
detect_on: "window",
events: {
onhover: {
enable: true,
mode: "repulse"
},
onclick: {
enable: true,
mode: "push",
},
resize: true
},
modes: {
grab: {
distance: 400,
line_linked: {
opacity: 1
}
},
bubble: {
distance: 400,
size: 40,
duration: 2,
opacity: 1,
speed: 3
},
repulse: {
distance: 150,
duration: 0.5
},
push: {
particles_nb: 20
},
remove: {
particles_nb: 2
}
}
},
retina_detect: true
}
export default particleConfig;
https://no-ganache--wolfgangfarming.netlify.app/ if anyone wants to see the actual website and inspect over there.
Thanks in advance