首页 > 解决方案 > 向上滑动前更改文本

问题描述

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

我该如何解决这个问题?

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

标签: jquery

解决方案


你需要使用动画的回调函数

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

推荐阅读