【发布时间】:2019-12-07 07:47:36
【问题描述】:
我创建了一个带有淡入淡出的图像幻灯片,它每秒自动循环播放。交叉淡入淡出效果很好,每次图像淡入和旧淡出时,其顶部位置都高于前一个。然后,在最终图像处,图像位置重置。
步骤:
1. 上边距:-575px
2. Margin-top:-600px(我假设)
3. Margin-top:-625px(我再次假设)
你明白了……它在上升,然后在第一张图像处重置
jQuery
$(function() {
var slides = [$("#image1"),$("#image2"), $("#image3"), $("#image4"), $("#image5")];
var slidePos = 0;
setInterval(function() {
if (slidePos < slides.length-1) {
slides[slidePos].animate({
opacity: "0"
}, 1000);
slides[slidePos+1].animate({
opacity: "1"
}, 1000, function() {
slidePos++;
});
} else {
marginCalc = 575;
slides[slidePos].animate({
opacity: "0"
}, 1000);
slidePos = 0;
slides[slidePos].animate({
opacity: "1"
}, 1000);
}
}, 3000);
});
相关的 CSS
.slideshow-container {
width: 100%;
background-color: yellow;
height: 100%;
text-align: center;
}
img {
width: 70%;
max-width: 800px;
margin: 0 auto 0 auto;
}
.transparent-image {
position: relative;
opacity: 0;
display: block;
margin-top: -50.5%;
}
#image1 {
opacity: 1;
margin-top: 0;
}
【问题讨论】:
-
不清楚问题出在哪里,您是想让图像上升还是这是一种意外效果?
-
上升是一种意想不到的效果,它应该保持原位。
标签: javascript jquery html css image