Showing a congrats picture in a win condition

Joined
Dec 12, 2022
Messages
1
Reaction score
0
Hello everyone, sorry I am new to this. I created a game using HTML/CSS/Java Script and I want to have a small "Congratulations, you won the game" image appears on the screen if I win the game ( Image, not text ). Then I want to have the image animated. The animation can be something as simple as the image moving around or rotating or something simple. Please guide me on how to accomplish this. Thanks :)
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
Well that's no big deal.

Here is a function of my own libary you may use.
Code:
function newElement(div,type,id,before,top){
  if(!div){
        div=document.getElementsByTagName('body')[0];
        }
    if(!type){
        type='DIV';
         }
    var node=document.createElement(type);
    if(id){node.id=id;}
    if(top){
        div.insertBefore(node, div.childNodes[0]);
           }else
    if(before){
       div.parentNode.insertBefore(node, div);
        }else{
    div.appendChild(node);
    }
    node.style.position='relative';
    
    return node;
    
}

and to remove Elements
Code:
function removeElement(d){
    if(d){d.innerHTML='';
    if(d.parentNode && d){
    d.parentNode.removeChild(d);
    }else{
        d.remove();
        }
    if(d){delete d; d=false;}
    }
}

Yes, it's a little bit outdated, but still woks for me (i did it almost 10 years ago, so have mercy)


With this functions you may create your congrats image
Code:
const congrats=newElement(false,'img');
congrats.src="yourcongratsimage.jpg";
congrats.style="yourstyles";
congrats.className="yourCSSClasses";
setTimeout(function(){removeElement(congrats);},15000); //remove that image after 15 Seconds.

The animation can be done by css.
Please use google first and try the result examples first, before asking for "how to do a rotation". Google already knows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top