I'm attempting to create an image cross fade effect using the following steps:
- Place the selected image in the front (position: -9999 to 0)
- Position the previous image in the back (position: 0 to -9999)
- Gradually increase the opacity of the selected image until it reaches 1
- Set the opacity of the previous image to 0 (to repeat the process)
Here is the code snippet:
<a-sky id="pano-1" src="image1" class="pano" opacity="0" position="-9999"></a-sky>
<a-sky id="pano-2" src="image2" class="pano" opacity="0" position="-9999"></a-sky>
var opacity = 0; // initial opacity
var step = 0.1; // step size
var target = 1; // target value
var time = 50; // delay in milliseconds
var increaseOpacity = setInterval(function () {
opacity = (opacity * 10 + step * 10) / 10;
if (opacity > target) {
clearInterval(increaseOpacity);
}
}, time);
$('#pano-${index}').attr('position', 0);
$('.pano').not('#pano-${index}').attr('position', -9999);
$('.pano').not('#pano-${index}').attr('opacity', 0);
The images are fading in and out, but not crossing each other (going from the old image to a white screen before the new image appears).
Is the order incorrect? How can I achieve the effect of the images seamlessly crossing over each other?