tengbao / vanta

Animated 3D backgrounds for your website
http://vantajs.com/
MIT License
5.55k stars 1.02k forks source link

Not Working #148

Open yinxiangshi opened 2 years ago

yinxiangshi commented 2 years ago

Hi, I am using Hugo to build my web, I got a very strange issue.

My code is:

<script src="/js/feather.min.js"></script>
<script src="/js/p5.min.js"></script>
<script src="/js/vanta.trunk.min.js"></script>
<script>
  feather.replace()
</script>
<script>
    VANTA.TRUNK({
    el: '#ele1',
    mouseControls: true,
    touchControls: true,
    gyroControls: false,
    minHeight: 200.00,
    minWidth: 200.00,
    scale: 1.00,
    scaleMobile: 1.00
    })
</script>
{{ define "main" }}
<div id="home-jumbotron" class="jumbotron text-center">
  <h1 class="title">{{ .Site.Title }}</h1>
</div>
<body>
    <div id=".ele1"></div>
</body>
{{ end }}

I got: vanta.trunk.min.js:1 [VANTA] Cannot find element #ele1

tengbao commented 2 years ago

change id=".ele1" to id="ele1"
also, make sure the vanta script runs after the dom is already loaded

yinxiangshi commented 2 years ago

This is also not working for me. On Fri, Nov 18, 2022 at 02:54 Teng Bao @.***> wrote:

change id=".ele1" to id="ele1"

— Reply to this email directly, view it on GitHub https://github.com/tengbao/vanta/issues/148#issuecomment-1319714589, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHUIB37ZWK6LS5H5V5BJFDLWI474PANCNFSM6AAAAAASBPP3XA . You are receiving this because you authored the thread.Message ID: @.***>

llPekoll commented 6 months ago

I have the same issue, did you manage to make it work?

FatalMerlin commented 3 months ago

@llPekoll , just had the same issue. Resolved by moving the VANTA script from head to body.

Before:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/vanta/dist/vanta.waves.min.js"></script>
        <script>
            VANTA.WAVES('#my-background');
        </script>
    </head>
    <body></body>
</html>

After:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/vanta/dist/vanta.waves.min.js"></script>
    </head>
    <body>
        <script>
            VANTA.WAVES('#my-background');
        </script>
    </body>
</html>

Not the most elegant, but works for now.