The following HTML allows the visitor to click on a thumbnail, then the JS script will make a larger version pop on in the “showImage” span. This works perfectly.
However, to make it appear more professional, how could I make it fade on quickly, going from opacity 0.5 to opacity 1.0? I have no idea how to relate it to the JS script.
Can you point me in a direction to create this effect? I don’t know if it’s possible.
< span id="showImage"></span>< br>< br>
< a href="#showImage" onclick="showImage('spraying')">< img id='spraying' class='thumb' src="../images/2016-offroad-sun_spraying.jpg" alt="Image"></a>
< a href="#showImage" onclick="showImage('champion2')">< img id='champion2' class='thumb' src="../images/2016-offroad-sun_champion2.jpg" alt="Image"></a>
< script>
function showImage(name) {
var list = document.getElementById('showImage'); // empty the span of previous image showing
if (list.hasChildNodes()) {
list.removeChild(list.firstChild);
}
var elem = document.createElement('img');
elem.style.width = '100%';
elem.style.maxWidth = '500';
elem.alt = 'Image from ...';
elem.title = 'Image from ...';
if (name === 'spraying') {elem.src = '../images/2016-offroad-sun_spraying.jpg';}
if (name === 'champion2') {elem.src = '../images/2016-offroad-sun_champion2.jpg';}
var showImage = document.getElementById('showImage');
showImage.appendChild(elem);
}
< /script>