向上滑动之前更改文本

时间:2018-09-10 08:29:23

标签: jquery

我正在制作带有文本和背景动画的滑块,但是下面的代码首先更改了文本,然后然后将其向上滑动。

我该如何解决?

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);

1 个答案:

答案 0 :(得分:1)

您需要使用动画的callback function

 $("#Fade").slideUp(1000, function() {
     // this runs after the animation has completed
     $("#text1").text(text1[index]);
     $("#text2").text(text2[index]);
     $("#Fade").slideDown(1000);
 });