particles.js 未正确加载到页面上 [英] particles.js not loading on page correctly
本文介绍了particles.js 未正确加载到页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML 脚本
<div id="particles-js"></div>
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
<script>
particlesJS.load('particles-js', 'particles.json',
function(){
console.log('particles.json loaded...')
})
</script>
粒子的 CSS
#particles-js {
margin-top: 100px;
width: 100vw;
height: 400px;
background: linear-gradient(45deg, #0ac8f8, #081866);
z-index: 9;
}
现在每当我加载页面时,我都会收到这些错误(在控制台中):
Now whenever I load the page I get these errors (in the console):
particles.min.js:9 Failed to load file:///G:/actualtest/particles.json: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
window.particlesJS.load @ particles.min.js:9
(anonymous) @ home.html:66
particles.min.js:9 Error pJS - XMLHttpRequest status: 0
particles.min.js:9 Error pJS - File config not found
推荐答案
正如@TemaniAfif 所指出的,这里缺少一个逗号:
As @TemaniAfif pointed out, there is a missing comma here:
<script>
particlesJS.load('particles-js', 'particles.json'
function(){
console.log('particles.json loaded...')'
})
</body>
...因为底部的内联函数是应该particleJS.load 函数调用的一个参数.它需要一个结束脚本标签.尝试将以上内容替换为:
...because the inline function at the bottom is supposed to be a parameter of the particleJS.load function call. And it needs a closing script tag. Try replacing the above with:
<script>
particlesJS.load('particles-js', 'particles.json',
function(){
console.log('particles.json loaded...')'
})
</script>
</body>
这篇关于particles.js 未正确加载到页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文