jeudi 18 juin 2020

Set width and height for image random by Javascript

Something hard to understand for me that, how can I set width and height for the random images when they displayed. Can anyone help me, please?

This is my code

    function randomImage(){
        var imagesArray = ['images/person1.jpg', 'images/person2.jpg', 'images/person3.jpg'];
        var num = Math.floor(Math.random() * 3);
        document.canvas.src = imagesArray[num];
    }
<!DOCTYPE html>
    <html lang="en">
        <head>
           <meta charset="UTF-8">
           <title>Display random image</title>
        </head>

        <body>
           <input type="button" id="randomImage" onclick="randomImage()" value="Random">
           <img src="" name="canvas" />
        </body>
      </html>

And I do not know how to set width and height so I did not write code for this yet, this code just display images random when I click button

Your help is my pleasure




Aucun commentaire:

Enregistrer un commentaire