我正在尝试使用particles.js作为网站的背景。当前,存在div粒子,但没有出现粒子。我该如何解决?
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="particles-js"></div>
<script type="text/javascript" src="./particles.js-master/demo/js/app.js"></script>
<script type="text/javascript" src="./particles.js-master/particles.js"></script>
</body>
</html>
style.css
body {
background: #000;
margin: 0;
padding: 0;
height: 100vh;
}
#particles-js {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
我知道存在particles-js,因为更改其背景颜色会对页面产生影响。
答案 0 :(得分:1)
您还需要添加粒子js配置才能正常工作。您可以从https://vincentgarreau.com/particles.js/
创建和下载json配置 try {
val intent = Intent()
val manufacturer = Build.MANUFACTURER
if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")
} else if ("oppo".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")
} else if ("vivo".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")
} else if ("Letv".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")
} else if ("Honor".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")
}
val uri = Uri.fromParts("package", context.getPackageName(), null)
intent.data = uri
val list = context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
if (list.size > 0) {
context.startActivity(intent)
}
} catch (e: Exception) {
Log.e("exc", e.toString())
}
例如,我的json可能如下所示:
<script type="text/javascript">
particlesJS("particles-js",<strong>Your JSON here</strong>);
</script>
答案 1 :(得分:1)
az
答案 2 :(得分:0)
非常感谢您的详细回复。但是万一有人再次看到这个问题,那就是我的adblocker不允许使用javascript粒子。