I'm very inexperienced with javascript and coding in general, so I've cobbled the below code together from a few examples I've seen here and elsewhere. The code does 90% of what I want now, but I am wondering how I can get it to display the first image in the array "videoFrames" before the slider is moved, as it is right now, the canvas is blank on page load. The second thing is that it doesn't seem like the images are loading on page load, am I wrong? How can I improve/incorporate that into this code?
var canvas = document.getElementById("myCanvas");
var width = 1920;
var height = 1080;
var totalImages = 50;
var videoFrames = [];
for (var i = 1; i <= totalImages; i++) {
var img = new Image;
var videoFrameUrl = 'https://the-faction.squarespace.com/assets/chalet-lightmix-01/Chalet-V06_LM_' + i + '.jpg';
img.src = videoFrameUrl;
videoFrames.push(img);
}
$("#my-input").on("input", function(event) {
var currentImage = videoFrames[event.target.value - 1];
var ctx = canvas.getContext("2d");
ctx.drawImage(currentImage, 0, 0, canvas.width, canvas.height);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="myCanvas" width="400" height="225" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<br>
<input id="my-input" type="range" min="1" max="50" value="0" />