我在我的代碼中有一個滑塊,它需要過渡,但它不起作用。CSS滑塊中的JS過渡
這裏是JS代碼 它也不能在CSS中工作... 當圖像變化時它需要轉換。我需要在滑塊中緩慢更改圖像。
其實我在JS嘗試這樣做:
document.getElementById("img").style.transition = "5s ease";
這裏是HTML
<div class="photo_div">
<img id="img" src="">
</div>
<button onclick="prev()">PREV</button>
<button onclick="next()">NEXT</button>
</div>
這裏是JS
var names = ["img1.jpg", "img2.jpg", "img3.jpg"];
var index = 0;
function init() {
document.getElementById("img").src = "photo/" + names[index];
autoSlide();
}
function next() {
index++;
if (index == names.length) {
index = 0;
}
document.getElementById("img").src = "photo/" + names[index];
}
function prev() {
if (index == 0) {
index = names.length
}
index--;
document.getElementById("img").src = "photo/" + names[index];
}
function autoSlide() {
if (index < names.length) {
setInterval(function() {
\t next();
}, 3000);
}
}
我已經添加了部件HTML代碼 – VCF
您試圖通過轉換實現什麼樣的效果?淡入淡出過渡?邊過渡? –
簡單過渡:過渡=「5s緩解」; – VCF