Define image size with random image code?

Viewed 28

At the moment I'm working with Elementor on Wordpress. What I'd like to do is have one of "modules" in Elementor filled with random images that also have each a different link to some page. I looked for a random image widget but those I found didn't provide a function to define a different link for each randomized image. So I decided to use the html widget on Elementor to use my own code. I'm not super skilled at this. So I have a code, the randomizing is working, so are the links but I don't know how to define a max. width for the images because they just fill the whole page with this code. My english isn't very good I hope someone might be able to help me and where to put something in the code to define the images size?

<!DOCTYPE html>
<html>
<head>

<script type="text/javascript">
  var imageUrls = [
       "IMAGE1“ 
     , "IMAGE2“
     , "IMAGE3“
  ];
 var imageLinks = [
       "LINK1“
      , "LINK2“
       , "LINK3“ 
  ];

  function getImageHtmlCode() {
    var dataIndex = Math.floor(Math.random() * imageUrls.length);
    var img = '<a href=\"' + imageLinks[dataIndex] + '"><img src="';        
    img += imageUrls[dataIndex];
    img += '\" alt=\"\"/></a>';
    return img;
  }
  

</script>
</head>
<script type="text/javascript">
  document.write(getImageHtmlCode());
</script>
</body>
0 Answers
Related