lundi 23 octobre 2017

Trying to use Javascript array to display Random images in

I'm not well know about javascripts, got this code from a website. Using javascript to display random images from array in div javascript working fine. But loaded images displays in random sizes tried using css style and all css html image attributes to resize them but nothing works, as they are displayed directly through javascript

want something to resize them directly in javascript

code main :

<script>    
           var arrayImg = new Array();
           arrayImg[0] = "a11.jpg";
           arrayImg[1] = "a12.jpg";


            getRandomImage(arrayImg, "");

          function getRandomImage(imgAr, path) {      
            path = path || 'images/'; // default path here
            var num = Math.floor( Math.random() * imgAr.length );
            var img = imgAr[ num ];
            var imgStr = '<img src="' + path + img + alt = "" >';
            document.writein(imgStr); 
            document.close();
            }

         </script> 

code I used to resize image : (but didn't work) :

<script>    
           var arrayImg = new Array();
           arrayImg[0] = "a11.jpg";
           arrayImg[1] = "a12.jpg";


            getRandomImage(arrayImg, "");

          function getRandomImage(imgAr, path) {      
            path = path || 'images/'; // default path here
            var num = Math.floor( Math.random() * imgAr.length );
            var img = imgAr[ num ];
            var img.height = 4vw;
            var img.width = 20%;
            var imgStr = '<img src="' + path + img + img.height + img.width + alt = "" >';
            document.writein(imgStr); 
            document.close();
            }

         </script>  

even tried using : (but still didn't work)

document.writeln('<td' + '><imgstr"' + height="180" width="160" border="0" ><' + '/td>');




Aucun commentaire:

Enregistrer un commentaire