DEV Community

ann lin
ann lin

Posted on

16 8

Wreck it Ralph 2 Virus Popup

I just watched Ralph Breaks the Internet 😍

and I absolutely love the scene where Ralph is popping everywhere on the screen.

Ralph in CSS

Because it's late and we need Ralph in CSS so I stole the amazing CSS pixel art by Jason Delia using box-shadow. We need to play with box-shadow again.

WRECK-IT-RALPH DEMO

Simple Popup Animation

Hide the original Ralph so the first Ralph is always at random position.

<div id="ralph"></div>

Duplicate Ralph using cloneNode and put it in body.

const body = document.getElementsByTagName("body")[0];
const ralph = document.getElementById("ralph");

function duplicateRalphAtRandomPosition() {
    const ralphClone = ralph.cloneNode(true);
    ralphClone.style.display = "block";
    ralphClone.style.top = getRandomPercentage();
    ralphClone.style.left = getRandomPercentage();
    ralphClone.style.transform = `scale(${getRandomSize()})`;
    body.appendChild(ralphClone);
}

Place cloned Ralph in random position with random size.

// Return 0% to 100%
function getRandomPercentage() {
    return Math.random() * 101 + "%";
}

// Return 0.3 - 1
function getRandomSize() {
    return Math.random() * 0.8 + 0.3;
}

Keep doing it every second until the Internet breaks using setInterval

// Duplicate Ralph every second yo
setInterval(function() {
    duplicateRalphAtRandomPosition();
}, 1000);

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay