Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle effect not getting affected in header division #98

Open
sayakpaul opened this issue Sep 3, 2017 · 1 comment
Open

Particle effect not getting affected in header division #98

sayakpaul opened this issue Sep 3, 2017 · 1 comment

Comments

@sayakpaul
Copy link

`<!doctype html>

<title>sketch.js » Basic Example</title>
    <link rel = "stylesheet" href  = "https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.css">

     <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    <style type="text/css">
        html, body {
            background: #222;
        }
    </style>
</head>
<body>
   
    
            <h2 class = "header center cyan-text">Ayushi, many many happy returns of the day! May the almighty give you every happiness that you want and deserve as well. Happy Birthday :') </h2><br><br>
            <center><a class="btn btn-floating btn-large pulse btn blue lighten-3" href = "https://i.imgur.com/acoUTOT.jpg" target="_blank"><i class="material-icons">child_care</i></a>
<script src="../js/sketch.js"></script> <script>
    // ----------------------------------------
    // Particle
    // ----------------------------------------

    function Particle( x, y, radius ) {
        this.init( x, y, radius );
    }

    Particle.prototype = {

        init: function( x, y, radius ) {

            this.alive = true;

            this.radius = radius || 10;
            this.wander = 0.15;
            this.theta = random( TWO_PI );
            this.drag = 0.92;
            this.color = '#fff';

            this.x = x || 0.0;
            this.y = y || 0.0;

            this.vx = 0.0;
            this.vy = 0.0;
        },

        move: function() {

            this.x += this.vx;
            this.y += this.vy;

            this.vx *= this.drag;
            this.vy *= this.drag;

            this.theta += random( -0.5, 0.5 ) * this.wander;
            this.vx += sin( this.theta ) * 0.1;
            this.vy += cos( this.theta ) * 0.1;

            this.radius *= 0.96;
            this.alive = this.radius > 0.5;
        },

        draw: function( ctx ) {

            ctx.beginPath();
            ctx.arc( this.x, this.y, this.radius, 0, TWO_PI );
            ctx.fillStyle = this.color;
            ctx.fill();
        }
    };

    // ----------------------------------------
    // Example
    // ----------------------------------------

    var MAX_PARTICLES = 280;
    var COLOURS = [ '#69D2E7', '#A7DBD8', '#E0E4CC', '#F38630', '#FA6900', '#FF4E50', '#F9D423' ];

    var particles = [];
    var pool = [];

    var demo = Sketch.create({
        container: document.getElementById( 'container' ),
        retina: 'auto'
    });

    demo.setup = function() {

        // Set off some initial particles.
        var i, x, y;

        for ( i = 0; i < 20; i++ ) {
            x = ( demo.width * 0.5 ) + random( -100, 100 );
            y = ( demo.height * 0.5 ) + random( -100, 100 );
            demo.spawn( x, y );
        }
    };

    demo.spawn = function( x, y ) {
        
        var particle, theta, force;

        if ( particles.length >= MAX_PARTICLES )
            pool.push( particles.shift() );

        particle = pool.length ? pool.pop() : new Particle();
        particle.init( x, y, random( 5, 40 ) );

        particle.wander = random( 0.5, 2.0 );
        particle.color = random( COLOURS );
        particle.drag = random( 0.9, 0.99 );

        theta = random( TWO_PI );
        force = random( 2, 8 );

        particle.vx = sin( theta ) * force;
        particle.vy = cos( theta ) * force;

        particles.push( particle );
    };

    demo.update = function() {

        var i, particle;

        for ( i = particles.length - 1; i >= 0; i-- ) {

            particle = particles[i];

            if ( particle.alive ) particle.move();
            else pool.push( particles.splice( i, 1 )[0] );
        }
    };

    demo.draw = function() {

        demo.globalCompositeOperation  = 'lighter';

        for ( var i = particles.length - 1; i >= 0; i-- ) {
            particles[i].draw( demo );
        }
    };

    demo.mousemove = function() {

        var particle, theta, force, touch, max, i, j, n;

        for ( i = 0, n = demo.touches.length; i < n; i++ ) {

            touch = demo.touches[i], max = random( 1, 4 );
            for ( j = 0; j < max; j++ ) {
              demo.spawn( touch.x, touch.y );
            }

        }
    };
    
    </script>
</body>
`

I am using above piece of code but the particle effect is getting started after the header. I want it to start from the top itself.

@awelles
Copy link

awelles commented Oct 11, 2017

Hey sayak,
Best not to seek general coding advice by opening an issue. But..

Put your h2 and button in a div, follow it with a div with id 'container', and set both to 'position:absolute' in their css. Then they'll overlap in the window.

So like this:

...
...
<body>
  <div style="position:absolute">
    <h2 class = "header center cyan-text">Ayushi, many many happy returns of the day! May the 
    almighty give you every happiness that you want and deserve as well. Happy Birthday :') </h2>
    <br><br><center><a class="btn btn-floating btn-large pulse btn blue lighten-3" href = 
    "https://i.imgur.com/acoUTOT.jpg" target="_blank"><i class="material-icons">child_care</i>
     </a></center>
  </div>
  <div id="container" style="position:absolute"></div>

<script>
...
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants