网页粒子背景插件 -Canvas-nest.js 指定具体位置展示

原文地址:https://blog.csdn.net/L1558198727/article/details/81121524

Canvas-nest.js是一个非常好看的网页粒子背景插件,不需要依赖任何第三方库即可运行,提供额非常炫酷的背景。但是默认的情况下是对整个body标签进行添加的,现在我们想让粒子指定具体的位置改怎么做呢?

①我们首先打开Canvas-nest.js官方的实现

(document.body, (f = document.getElementsByTagName("script"), {
        zIndex: (y = f[f.length - 1]).getAttribute("zIndex"),
        opacity: y.getAttribute("opacity"),
        color: y.getAttribute("color"),
        count: Number(y.getAttribute("count")) || 99
    }))

 

在最后的地方对这个实现的函数进行了调用,这里的参数是body,效果如下

这里写图片描述

②我们可以在这个将document.body替换成其他的元素,例如

html代码

<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>CanvasDemo</title>
</head>

<body>
    <div id="cas" style="position: absolute;width: 200px;height: 200px; left: 200px; z-index: 99999;"></div>
    <script src="dist/canvas-nest.js" type="text/javascript" color="255,0,0" opacity="0.5" count="200" ></script>

</body>
</html>

 

Canvas-nest.js中做如下修改

(document.getElementById("cas"), (f = document.getElementsByTagName("script"), {
        zIndex: (y = f[f.length - 1]).getAttribute("zIndex"),
        opacity: y.getAttribute("opacity"),
        color: y.getAttribute("color"),
        count: Number(y.getAttribute("count")) || 99
    }))

 

即可限制例子出现的位置

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值