我正在制作一个带有文本和背景动画的 slider ,但下面的代码首先更改文本,然后将其向上滑动。
如何解决这个问题?
var index = 0;
var images = ["images/mainimage.jpg", "images/rampcustomers.jpg"];
var text1 = ["Connect all your devices and data bases", "Lorem ipsum dolor sit amet,"];
var text2 = ["Keep the efficiency managed and always up-to-date", "Lorem ipsum dolor sit amet"];
setInterval(function() {
index++;
if (index >= 2) {
index = 0;
}
$('#container1').animate({
opacity: 0.5
}, 'slow', function() {
$(this).css({
'background-image': 'url(' + images[index] + ')'
})
.animate({
opacity: 1
});
});
$("#Fade").slideUp(1000);
$("#text1").text(text1[index]);
$("#text2").text(text2[index]);
$("#Fade").slideDown(1000);
}, 4000);
最佳答案
您需要使用callback function动画:
$("#Fade").slideUp(1000, function() {
// this runs after the animation has completed
$("#text1").text(text1[index]);
$("#text2").text(text2[index]);
$("#Fade").slideDown(1000);
});
关于jquery - 向上滑动之前更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52253820/