Making Toast Message using HTML CSS JS

 Making Toast Message using HTML CSS JS


HTML CODE

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <button id="btn">
        Click
    </button>
    <div id="toast">
        
    </div>
    <script src="script.js"></script>
</body>
</html>
CSS CODE

*{
    margin0;
    padding0;
    box-sizingborder-box;
}

#btn{
    padding14px 17px;
}

.toast{
    min-width250px;
    margin-left-125px;
    background#333;
    color:#fff;
    text-aligncenter;
    border-radius2px;
    padding16px;
    positionfixed;
    z-index1;
    left50%;
    top:30px;
    animation: fadein 0.5s;
}

@keyframes fadein{
    from{top:0;opacity:0;}
    to{top:30px;opacity1;}
}
JAVASCRIPT

const btn=document.getElementById("btn");
const container =document.getElementById("toast");
btn.addEventListener('click',show);

function show(){
    const box =document.createElement("div");
    box.innerText="Message Display ...";
    box.classList.add("toast");
    btn.disabled=true;
    container.appendChild(box);
    btn.innerText="wait...";
    setTimeout(()=>{
        box.remove();
        btn.disabled=false;
        btn.innerText="Click";
    },3000)
}

Comments

Popular posts from this blog

Write a program to find sum of first 10 natural number in java

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java

Write a program to check a year is leap year or not in java