javascript - particles.js not loading on page correctly - Stack Overflow

HTML script <div id="particles-js"><div><script src=".js2.0.0partic

HTML script

<div id="particles-js"></div>
<script src=".js/2.0.0/particles.min.js"></script>
<script>
    particlesJS.load('particles-js', 'particles.json',
    function(){
        console.log('particles.json loaded...')
    })
</script>

CSS for the particles

#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

HTML script

<div id="particles-js"></div>
<script src="https://cdn.jsdelivr/particles.js/2.0.0/particles.min.js"></script>
<script>
    particlesJS.load('particles-js', 'particles.json',
    function(){
        console.log('particles.json loaded...')
    })
</script>

CSS for the particles

#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
Share Improve this question edited May 14, 2018 at 21:19 Adam Kerik asked May 14, 2018 at 20:27 Adam KerikAdam Kerik 4916 silver badges15 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 2

As @TemaniAfif pointed out, there is a missing ma here:

<script>
    particlesJS.load('particles-js', 'particles.json'
    function(){
        console.log('particles.json loaded...')'
    })
</body>

...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>

please try following code:

<script>
particlesJS.load('particles-js', 'particles.json',
    function(){
        console.log("particles.json loaded...");
    });
</script>

Did you saved the "particle.json" file correctly in your root directory where your application runs?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745107041a4611621.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信