div工作不正常

时间:2017-10-09 17:52:23

标签: javascript html css particle.js

我制作了一个我想要限制的粒子效果,使其覆盖整个屏幕(而不是整个网页),以便创建视差类型效果。问题是我可以用像素限制高度但是当我尝试使用高度时:100vh; div class =" main tag"没有出现。 有什么帮助吗?

这是我的HTML:

<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>A Pen by  Rithik Kapoor </title>



      <link rel="stylesheet" href="css/style.css">


</head>

<body>
  <head>
<link href='https://fonts.googleapis.com/css?family=Righteous' rel='stylesheet' type='text/css'>
</head>
<body>
  <section>
<div class="main" id="particles-js">
  <center>
    <div class="whole">
  <div class="wrap">
    v
  </div>
  <p>
  COMP D' AFFAIRES<p></center>

    </div>
</div>
</section>
  <div id="box">
    lol
  </div>

  <script src='https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js'></script>

    <script  src="js/index.js"></script>


</body>
</html>

我的CSS:

html{
  width:100%;
  height:100%;
  overflow:hidden;
}
body{
  margin:0;
  padding:0;
  width:100%;
  font-rendering:optimizeLegibility;
      -webkit-font-smoothing: antialiased;
  height:100%;
  font-family: 'Righteous', cursive;
  color: white;
  font-size: 100px;
}
.main{
  width:100%;
  height:100vh;
  background: #000000;
  background-attachment: fixed;
  background-size:cover;
  display:table;

}
.wrap{
  font-size: .7em;
  overflow: hidden;
  margin:0;
  width: 100px;
  height:100px;
  border-radius: 100%;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  -webkit-transition:all 0.3s ease;
  transition: all 0.3s ease;
  position: absolute;
  left:400px;
  bottom: -100px;
  padding: 0px;
  margin: 0px;

}
.wrap:hover{
  box-shadow: 0px 0px 0px 8px #4F5E7F;
  border: solid 4px #965F8A;

}
.wrap img{
  width:100%;
}
.whole{
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
}

#box {
  background-color:black;
  height:100vh;
  width:100%;
  background-attachment: fixed;
  background-size:cover;
  display:table;
  z-index:1000000;

}

我的javascript:

particlesJS("particles-js", {
  "particles": {
    "number": {
      "value": 80,
      "density": {
        "enable": true,
        "value_area": 800
      }
    },
    "color": {
      "value": "#11ff00"
    },
    "shape": {
      "type": "circle",
      "stroke": {
        "width": 0,
        "color": "#000000"
      },
      "polygon": {
        "nb_sides": 5
      },
      "image": {
        "src": "img/github.svg",
        "width": 100,
        "height": 100
      }
    },
    "opacity": {
      "value": 0.9,
      "random": false,
      "anim": {
        "enable": false,
        "speed": 1,
        "opacity_min": 0.1,
        "sync": false
      }
    },
    "size": {
      "value": 4,
      "random": true,
      "anim": {
        "enable": false,
        "speed": 40,
        "size_min": 0.1,
        "sync": false
      }
    },
    "line_linked": {
      "enable": true,
      "distance": 150,
      "color": "#ff0000",
      "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
});

/* ---- stats.js config ---- */

var count_particles, stats, update;
stats = new Stats;
stats.setMode(0);
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
document.body.appendChild(stats.domElement);
count_particles = document.querySelector('.js-count-particles');
update = function() {
  stats.begin();
  stats.end();
  if (window.pJSDom[0].pJS.particles && window.pJSDom[0].pJS.particles.array) {
    count_particles.innerText = window.pJSDom[0].pJS.particles.array.length;
  }
  requestAnimationFrame(update);
};
requestAnimationFrame(update);

1 个答案:

答案 0 :(得分:0)

你正在使用溢出:隐藏在这里看

html{
  width:100%;
  height:100%;
  overflow:hidden;
}

删除此溢出:隐藏 并看出来 Here is the working fiddle