我想用fadeIn和fadeOut方法創建一個使用JS的幻燈片。問題是下一張圖像會淡入,但前一張圖像不會淡出。如何在JS中淡出圖像?
我想切換位置風格的JS代碼,以便當網站加載容器將接受裏面的內容,並會相應地放大。
我創建了一個功能來切換位置的風格。
這是我到目前爲止有:
$(document).ready(function() {
$("#slideshow > div:gt(0)").hide();
function toggle() {
document.getElementById("img").style.position = "absolute";
}
setInterval(function() {
$('#slideshow > div:first')
.toggle()
.fadeOut(1500)
.next()
.fadeIn(1500)
.end()
.appendTo('#slideshow');
}, 5000);
});
#slideshow {
position: relative;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
width: 100%;
height: auto;
}
.center-img {
image-orientation: from-image;
position: relative;
margin: auto;
width: 100%;
height: auto;
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<div id="slideshow">
<div id="slideshow_div"> <img class="center-img" src="http://i.imgur.com/RRUe0Mo.png"> </div>
<div id="slideshow_div"> <img class="center-img" src="http://keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg"> </div>
</div>
我只是不知道如何讓圖像褪色,在未來一個之前淡出
感謝。 in advanced
爲什麼要切換位置CSS元素的原因是,圖像與瀏覽器正確縮放,容器將重新構建圖像。 –
請參閱更新的答案。如果您使用jQuery,則不需要使用getElementById – evilpenguin