Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change button size for a short period of time in web

So, as you see, I’m doing a clicker project. But I encounter a problem, when I tried to change the button size for a while on click, it doesn’t play the animation. Also, I want my button to change SIZE not WIDTH. So can you guys help me?

So, here’s my HTML:

<html>
    <head>
        <title>This is just test</title>
        <script src="clicker.js"></script>
        <link rel="stylesheet" href="clicker.css">
    </head>
    <body>
        <p id="title">Clicker Test</p>
        <div id="button">
            <span id="text">Score:</span>
            <span id="score">0</span>
        </div>
        <script>
            let counter = 0;
  
            document.getElementById('button').onclick = () => {
                document.getElementById('button').style.width = '45%';
                document.getElementById('button').style.width = '50%'
                counter = counter + 1;
                document.getElementById('score').innerText = counter;
            };
        </script>
    </body>
</html>

And CSS(if you want):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap');

body{
    background: linear-gradient(to right, #11998e, #38ef7d)
}

#title{
    text-align: center;
    font-family: 'Montserrat';
    font-size: 48px;
    font-weight: bold;
    user-select: none;
    margin-top: 2%;
}

#button{
    margin: auto;
    width: 50%;
    height: auto;
    padding: 15px;
    text-align: center;
    border: 3px solid white;
    border-radius: 50px;
    font-family: 'Montserrat';
    font-size: 32px;
    font-weight: bold;
    user-select: none;
    transition-duration: 0.15s;
}

#button:hover{
    margin: auto;
    width: 50%;
    padding: 15px;
    text-align: center;
    border: 3px solid white;
    background-color: white;
    border-radius: 50px;
    font-family: 'Montserrat';
    font-size: 32px;
    font-weight: bold;
    user-select: none;
    cursor: pointer;
    transition-duration: 0.15s;
}

>Solution :

CSS Animation onClick

This question might help you. Just create a class with :active pseudoclass. Then create an animation and assign that class to your button.

If you do everything right, your animation will run when you click your button.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading