Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header style="position: sticky; top: 0; height: 50px; background-color: #ff0033;">Header</header>
<section style="background-color: #bbb; height: 50vh;"></section>
<div class='contenitore' id="contenitore">
  <div class='contenitore-tasti'>
    <button class='icona'>Button 1</button>
    <button class='icona'>Button 2</button>
  </div>
  <div class='emitter' id='emitter1'></div>
  <div class='emitter' id='emitter2'></div>
</div>
              
            
!

CSS

              
                .contenitore {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    height: 400px;
    background-color: #ccc;
}
.contenitore-tasti {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #ddd;
}
.contenitore-tasti button:nth-of-type(1) {
    transform: translateX(-100px);
}
.contenitore-tasti button:nth-of-type(2) {
    transform: translateX(100px);
}
button.icona::before {
    display: inline-block;
    font-style: normal;
    font-variant: normal;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    margin-right: 10px;
}
button {
    padding: 15px 25px;
    border: 0;
    border-radius: 0;
    text-transform: uppercase;
    font-size: 20px;
    z-index: 0;
}
.emitter {
    width: auto;
    display: block;
    position: absolute;
    font-size: 20px;
    width: 20px;
    height: 20px;
}
#emitter1 {
    transform: translateX(-20px);
    background-color: rgba(0, 255, 100, 0.3);
}
#emitter2 {
    transform: translateX(20px);
    background-color: rgba(255, 0, 0, 0.3);
}
.dot {
    background-color: blue;
    border-radius: 50%;
    position: absolute;
    top:0;
    left:0;
    z-index: 5000;
    pointer-events: none;
}
              
            
!

JS

              
                var tl1 = gsap.timeline({ repeat: -1, repeatDelay: 3 });
tl1.from("#emitter1", { x:0, y: 0, duration: 0 });
tl1.to("#emitter1", { y: 190, duration: 1 });
tl1.to("#emitter1", { x: -150, duration: 1 });
tl1.to(".contenitore-tasti button:nth-of-type(1)", { 'border': '1px solid #0070C0', duration: 0.15 });
tl1.to(".contenitore-tasti button:nth-of-type(1)", { 'border': 'unset', duration: 0.2, delay: 1 });
/*
var tl2 = gsap.timeline({repeat: -1, repeatDelay: 3});
tl2.to("#emitter2", {y: 190, duration: 1});
tl2.to("#emitter2", {x: 150, duration: 1});
tl2.to(".contenitore-tasti button:nth-of-type(2)", {'border': '1px solid #BF0404', duration: 0.15});
tl2.to(".contenitore-tasti button:nth-of-type(2)", {'border': 'unset', duration: 0.2, delay: 1});
*/

//particle animation with dots defined by css .dot
var emitter1 = document.getElementById("emitter1"),
    emitter2 = document.getElementById("emitter2"),
    emitters = [emitter1, emitter2],
    //the following variables make things configurable. Play around.
    emitterSize = 20,
    dotPool = [],
    dotIndex = 0,
    dotQuantity = 125,
    dotSizeMax = 8,
    dotSizeMin = 1,
    speed = -1,
    gravity = 0;

//emitter's size dynamic and set xPercent/yPercent to -50 to accurately center it.
emitters.forEach(async (em) => {
    TweenLite.set(
        em, {
        width: emitterSize,
        height: emitterSize,
        xPercent: 0,
        yPercent: 0,
        //x: 0,
        //y: 0,
    });
    createDot(em);
});

function createDot(emitter) {
    dotPool[emitter.id] = [];

    for (var i = dotQuantity - 1; i >= 0; i--) {
        dot = document.createElement("div");
        dot.className = "dot";
        if (emitter.id === 'emitter1')
            dot.className += " dot-luce";
        else if (emitter.id === 'emitter2')
            dot.className += " dot-gas";
        TweenLite.set(
            dot, {
            xPercent: 0,
            yPercent: 0,
            // x: 0,
            // y: 0,
            force3D: true
        });
        //document.body.appendChild(dot);
        // document.getElementById(emitter.id).appendChild(dot);
        document.getElementById('contenitore').appendChild(dot);
        // document.body.appendChild(dot);
        // dotPool[i] = dot;
        dotPool[emitter.id][i] = dot;
    }
}
// console.log(dotPool);
// var explosion1 = new TimelineMax({ repeat: -1 }).call(shootDot, [emitter1], null, 2 / dotQuantity);
var explosion1 = new TimelineMax({ repeat: -1 }).call(shootDot1, [emitter1], null, 2 / dotQuantity);
//var explosion2 = new TimelineMax({ repeat: -1 }).call(shootDot2, [emitter2], null, 2 / dotQuantity);

function shootDot1(emitter1) {
    var angle, length, dot, i, size, bounds;
    // bounds = emitter1.getBoundingClientRect();
    bounds = document.getElementById("contenitore").getBoundingClientRect();
    dot = dotPool[emitter1.id][dotIndex++];
    //create all the dots
    if (dotIndex === dotQuantity) dotIndex = 0;
    size = getRandom(dotSizeMin, dotSizeMax);
    angle = Math.random() * Math.PI * 2; //random angle
    //figure out the maximum distance from the center, factoring in the size of the dot (it must never go outside the circle), and then pick a random spot along that length where we'll plot the point. 
    length = Math.random() * (emitterSize / 2 - size / 2);
    //place the dot at a random spot within the emitter, and set its size.
    TweenLite.set(dot, {
        opacity: 1,
        //x: 0,
        //y: 0,
        x: Math.cos(angle) * length + bounds.left + bounds.width / 2,
        y: Math.sin(angle) * length + bounds.top + bounds.height / 2,
        width: size,
        height: size
    });
    // console.log(Math.cos(angle) * length + bounds.left + bounds.width / 2, Math.sin(angle) * length + bounds.top + bounds.height / 2);
    //this is where we do the animation...
    TweenLite.to(dot, 1 + Math.random(), {
        opacity: 0,
        //if you'd rather not do physics, you could just animate out directly by using the following 2 lines instead of the physics2D:
        //x:Math.cos(angle) * length * 6, 
        //y:Math.sin(angle) * length * 6
    }, 0);
}

function shootDot2(emitter2) {
    var angle, length, dot, i, size, bounds;
    bounds = document.getElementById("contenitore").getBoundingClientRect();
    dot = dotPool[emitter2.id][dotIndex++];
    //create all the dots
    if (dotIndex === dotQuantity) dotIndex = 0;
    size = getRandom(dotSizeMin, dotSizeMax);
    angle = Math.random() * Math.PI * 2; //random angle
    //figure out the maximum distance from the center, factoring in the size of the dot (it must never go outside the circle), and then pick a random spot along that length where we'll plot the point. 
    length = Math.random() * (emitterSize / 2 - size / 2);
    //place the dot at a random spot within the emitter, and set its size.
    TweenLite.set(dot, {
        opacity: 1,
        x: bounds.width / 2,
        y: 0,
        //x: Math.cos(angle) * length + bounds.left + bounds.width / 2,
        //y: Math.sin(angle) * length + bounds.top + bounds.height / 2,
        width: size,
        height: size
    });
    // console.log(Math.cos(angle) * length + bounds.left + bounds.width / 2, Math.sin(angle) * length + bounds.top + bounds.height / 2);
    //this is where we do the animation...
    TweenLite.to(dot, 1 + Math.random(), {
        opacity: 0,
        //if you'd rather not do physics, you could just animate out directly by using the following 2 lines instead of the physics2D:
        //x:Math.cos(angle) * length * 6, 
        //y:Math.sin(angle) * length * 6
    }, 0);
}

function getRandom(min, max) {
    return min + Math.random() * (max - min);
}
              
            
!
999px

Console