particle.js不能覆盖整个页面 [英] particles.js not covering entire page

查看:58
本文介绍了particle.js不能覆盖整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 particles.js 作为背景,但是我无法将画布设置为全尺寸背景.

I'm trying to use particles.js as background, but I am not able to set the canvas as a full-size background.

我尝试了类似问题的至少10种不同解决方案,但没有任何效果.画布始终作为具有宽高比的元素出现在屏幕上,但是在调整大小时并不能覆盖画布的整体.在上瘾时,它不会作为背景,而是作为身体的一部分,位于其余元素之上或之下.

I tried at least 10 different solution from similar issues but nothing worked. The canvas always results as as an element having width-height ratio as the screen but it doesn't cover it as a whole when it is resized. In addiction, it won't set as background but as a child of the body, over or below the remaining elements.

我尽可能地简化了代码,问题仍然存在.

I simplified the code as much as possible and the problem still persist.

问题示例

HTML

<!DOCTYPE HTML>

<html>
    <head>
        <title>Try</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <link rel="stylesheet" media="screen" href="css/style.css">
    </head>

    <body>
        <div id="particles-js"></div>
        <div>
            <p>Something here</p>
        </div>
    </body>

    <script src="assets/js/particles.js"></script>
    <script src="assets/js/app.js"></script>
</html>

CSS

canvas{
  display:block;
  vertical-align:bottom;
  position: absolute;
}

/* ---- particles.js container ---- */

#particles-js{
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: #b61924;
  background-image: url('');
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  top: 0;
}

可以从之前发布的所有者的网站上下载

APP.JS和PARTICLES.JS.我正在使用它们当前所在的主题

APP.JS and PARTICLES.JS can be downloaded from the owner's website posted before. I'm using themas they are at the moment

感谢您的帮助

推荐答案

好吧,我终于解决了背景问题:这就是我的管理方式(我很确定我已经尝试过了,但是如果最终可以重新构建整个html)

Ok I finally solved the background question: That's how I managed it (I'm pretty sure I had already tried that but re-building the whole html if finally worked)

CSS

#particles-js{
  width: 100%;
  height: 100%;
  position: fixed;
  background-color: #000;
  background-image: url('');
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
}

.body-particles{
  position: absolute;
  top: 0;
  left: 0;
  z-index: 100;
}

HTML

<html>
    <head>
        <title>Title</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />

        <!-- SOME CSSs HERE -->

        <link rel="stylesheet" media="screen" href="assets/css/particles.css">

         <!-- SOME SCRIPTS HERE -->
    </head>
    <body>
        <div class="body-particles">

        <!-- Wrapper -->
            <div id="wrapper">
                <!-- MY STUFF HERE, STYLED WITH MY CSS -->
            </div>
        </div>

        <!-- particles.js container -->
        <div id="particles-js"></div>

        <!-- scripts -->
        <script src="assets/js/particles.js"></script>
        <script src="assets/js/app.js"></script>

    </body>
</html>

现在,我有一个新问题:被设置为基础层,它不捕获任何指针事件.一旦使它起作用,我将更新答案.

Now, I have a new problem: being set as an underlying layer, it catch no pointer-events. As soon as I will make it works, I'll update the answer.

很明显,如果您有任何建议,请随时提供帮助.

Obviously, feel free to help if you have any suggestion.

更新:mouseEvents的解决方法:将class mouseEvents添加到我需要关注的元素(例如navbar等)

UPDATE: Workaround for mouseEvents: Adding class mouseEvents to elements I need to focus (for example , navbar, etc.)

CSS

.body-particles{
  pointer-events: none;
}

.mouseEvents{
  pointer-events: all;
}

但是,如果有人知道将事件保留在正面和背面的更好方法,那就太好了

However, it would be nice if someone knows a better way to keep events both in front and back layer

这篇关于particle.js不能覆盖整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆