I am new to CoffeeScript and JavaScript so I am having some trouble displaying some images sequentially in a html file by changing the src attribute of an <img> tag. This is the code I have:
#START: Loop to show all the images of the folder
i = 0
show_images = (folder, start_idx, end_idx) ->
if start_idx <= end_idx
$('#video')
.attr 'src', "/media/generated#{folder}generated#{start_idx}.jpg"
i += 1
setTimeout ->
show_images(folder, start_idx+i, end_idx)
, 50
#START: Loop to show all the images of the folder
I believe this fails because CoffeeScript as JavasCript does not run Syncronously, however I haven’t been able to figure out how to accoplish the desired task.
You don’t need the
ivar. Try this: