WordPress Hosting
Free Photos
WordPress Themes

JavaScript image spinner

//JAVASCRIPT <script> var imagesArray = ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg", "image6.jpg", "image7.jpg", "image8.jpg"]; var gen_nums = []; function in_array(array, el) { for(var i = 0 ; i < array.length; i++) if(array[i] == el) return true; return false; } function displayImage(){ var num = Math.floor(Math.random() * 8); document.canvas.src = 'img/'+ imagesArray[num]; } function displayImageND(){ var num = Math.floor(Math.random() * 8); if(!in_array(gen_nums, num)) { gen_nums.push(num); return document.canvas.src = 'img/'+ imagesArray[num]; } return displayImageND(); } </script> //HTML <div class="row"> <div class="container"> <form name="imageForm"> <table border=3> <tr> <td> <input onclick="displayImageND();" type="button" value="SPIN (zonder dubbele weergave)"> </td> </tr> <tr> <td> <img src="img/image1.jpg" name="canvas" id="canvas" /> </td> </tr> </table> <div class="btn btn-outline-success btn-spin" onclick="displayImage();">SPIN!</div> </form> </div> </div>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.