#nyan cat snippet

1 messages ยท Page 1 of 1 (latest)

versed berry
#

cool, one problem, it prevents selecting and clicking, css could fix the problem

rotund shadow
versed berry
#

ik, just notifying the creator

timid mesa
timid mesa
#

as he said tho, you can just:

// summons nyan
const nyanCat = document.createElement('div');
nyanCat.id = 'nyan-cat';
document.body.appendChild(nyanCat);

const nyanCatStyles = `
    #nyan-cat {
        position: absolute;
        width: 150px;
        height: 75px;
        background-image: url('https://static.wikia.nocookie.net/nyancat/images/b/b9/OriginalNyan.gif');
        background-size: contain;
        background-repeat: no-repeat;
        z-index: 9999;
        pointer-events: none;  /* this makes it not affect clicking */
    }
`;

const styleSheet = document.createElement('style');
styleSheet.type = 'text/css';
styleSheet.innerText = nyanCatStyles;
document.head.appendChild(styleSheet);

// sets initial position and velocity
let posX = Math.random() * (window.innerWidth - 150);
let posY = Math.random() * (window.innerHeight - 75);
let velocityX = 2;
let velocityY = 2;

function updateNyanCatPosition() {
    posX += velocityX;
    posY += velocityY;

    // makes it bouncy
    if (posX <= 0 || posX >= window.innerWidth - 150) {
        velocityX = -velocityX;
    }
    if (posY <= 0 || posY >= window.innerHeight - 75) {
        velocityY = -velocityY;
    }

    nyanCat.style.transform = `translate(${posX}px, ${posY}px)`;

    requestAnimationFrame(updateNyanCatPosition);
}

// starts the animation
requestAnimationFrame(updateNyanCatPosition);
tough berry
#

Seems to no longer work?

versed berry
#

cuz it's pure js code basically doesn't depend on anything

tough berry
#
Refused to load the image 'https://static.wikia.nocookie.net/nyancat/images/b/b9/OriginalNyan.gif' because it violates the following Content Security Policy directive: "img-src 'self' blob: data: https://*.discordapp.net https://*.discordapp.com https://*.discord.com https://i.scdn.co https://i.ytimg.com https://i.imgur.com https://media.tenor.co https://media.tenor.com https://c.tenor.com https://*.youtube.com https://*.giphy.com https://static.klipy.com https://static-cdn.jtvnw.net https://pbs.twimg.com https://assets.braintreegateway.com https://checkout.paypal.com https://api.cash.app https://*.mux.com blob: data: vencord: vesktop: http://localhost:* http://127.0.0.1:* localhost:* 127.0.0.1:* *.github.io github.com raw.githubusercontent.com *.gitlab.io gitlab.com *.codeberg.page codeberg.org *.githack.com jsdelivr.net i.imgur.com i.ibb.co i.pinimg.com *.tenor.com files.catbox.moe cdn.discordapp.com media.discordapp.net cdnjs.cloudflare.com cdn.jsdelivr.net *.vencord.dev manti.vendicated.dev ugc.decor.fieryflames.dev dearrow-thumb.ajay.app usrbg.is-hardly.online icons.duckduckgo.com".```
versed berry
#

oh alr

#

do you have a github or smth?

#

@tough berry you should be able to upload the gif to some of those domains and you will be fine

tough berry
#

Alright, will try that some time ^^