漂亮的动态气泡背景效果bubbly-bg.js

栏目: Html5 · 发布时间: 6年前

内容简介:bubbly-bg.js是一款漂亮的动态气泡背景js插件。它是基于HTML5 canvas,压缩后的版本小于1kb,但是它能制作出各种漂亮的动态气泡背景效果,非常强大。

bubbly-bg.js是一款漂亮的动态气泡背景js插件。它是基于HTML5 canvas,压缩后的版本小于1kb,但是它能制作出各种漂亮的动态气泡背景效果,非常强大。

查看演示 下载源码

使用

可以通过npm来安装bubbly-bg.js动态气泡背景插件。

npm install bubbly-bg --save

可以在页面中引入bubbly-bg.js文件。

<script type="text/javascript" src="path/to/js/bubbly-bg.js"></script>

HTML结构

如果你不指定 <canvas> 元素作为容器,而是直接在 body 中初始化插件,那么插件会在body之后创建一个<canvas>元素,这个元素具有 position: fixedz-index: -1 属性,并且它的宽度和高度始终会等于视口的宽度和高度。例如:

<body>
  ...
  <script src="js/bubbly-bg.js"></script>
  <script>bubbly();</script>
</body>

你也可以指定一个 <canvas> 作为动态气泡背景的容器。例如:

<canvas id="demo" width="400" height="300"></canvas>

然后通过下面的方法来初始化。

bubbly({
  canvas: document.getElementById("demo")
});

配置参数

bubbly-bg.js动态气泡背景插件的可用配置参数有:

bubbly({
    animate: false, // default is true
    blur: 1, // default is 4
    bubbleFunc: () => `hsla(${Math.random() * 360}, 100%, 50%, ${Math.random() * 0.25})`, // default is () => `hsla(0, 0%, 100%, ${r() * 0.1})`)
    bubbles: 100, // default is Math.floor((canvas.width + canvas.height) * 0.02);
    canvas: document.querySelector("#background"), // default is created and attached
    colorStart: "#4c004c", // default is blue-ish
    colorStop: "#1a001a",// default is blue-ish
    compose: "lighter", // default is "lighter"
    shadowColor: "#0ff", // default is #fff
});

示例,黄色/粉色带红色/橙色/黄色气泡效果:

bubbly({
    colorStart: "#fff4e6",
    colorStop: "#ffe9e4",
    blur: 1,
    compose: "source-over",
    bubbleFunc: () => `hsla(${Math.random() * 50}, 100%, 50%, .3)`
});

该项目的github地址: https://github.com/tipsy/bubbly-bg .


以上所述就是小编给大家介绍的《漂亮的动态气泡背景效果bubbly-bg.js》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Chinese Authoritarianism in the Information Age

Chinese Authoritarianism in the Information Age

Routledge / 2018-2-13 / GBP 115.00

This book examines information and public opinion control by the authoritarian state in response to popular access to information and upgraded political communication channels among the citizens in co......一起来看看 《Chinese Authoritarianism in the Information Age》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码