0
如何在圖片發生變化時添加淡入或淡出效果,當您點擊下一張圖片時?我在這裏使用畫布。我沒有使用自動幻燈片,也沒有使用超時。基本上,它在圖像轉換過程中增加了效果。如何在javascript中點擊時添加淡入淡出效果?
function nextimg() {
i++;
if(i > 0 && i < 6) {
image.src = 'images/' + i + '.jpg';
}
if(msg1 == i) {
msg = "Fallout 4";
document.getElementById("caption").innerHTML = msg;
}
else if(msg2 == i) {
msg = "Diamond City";
document.getElementById("caption").innerHTML = msg;
}
else if(msg3 == i) {
msg = "Commonwealth";
document.getElementById("caption").innerHTML = msg;
}
else if(msg4 == i) {
msg = "Glowing Sea";
document.getElementById("caption").innerHTML = msg;
}
else if(msg5 == i) {
msg = "Cambridge";
document.getElementById("caption").innerHTML = msg;
}
var canvas = document.getElementById("img_1").className += "fadeOutEffect";
var canvas = document.getElementById("img_1");
var context = canvas.getContext("2d");
context.drawImage(image, 0,0, 500, 400);
}
==================================
#prevpic {
opacity:1;
transition: opacity 1s;
}
#nextpic.fadeOutEffect {
opacity:0;
}
== ===============================
<h2 id="caption"></h2>
<canvas id="img_1" width="500" height="400">
<--!input type="submit" onclick="canvas(); return false;"!-->
</canvas><br><br>
<input type="submit" id="prevpic" value="Previous" onclick="previmg()">
<input type="submit" id="nextpic" value="Next" onclick="nextimg()">