owais latif
owais latif

Reputation: 61

Text changing before slide up

I am making a slider with text and background animation but the code below is first changing the text and then sliding it up.

How do I resolve this?

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

Upvotes: 2

Views: 203

Answers (1)

Pete
Pete

Reputation: 58412

You need to use the callback function of the animation:

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

Upvotes: 1

Related Questions